-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(node): Add dataloader
integration
#13664
Merged
+152
−0
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Loading status checks…
feat(node): Add
dataloader
instrumentation
commit fb171b082e738a97e0df46b7bcb1b1a734b9a32c
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
dev-packages/node-integration-tests/suites/tracing/dataloader/scenario.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { loggingTransport, startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
const PORT = 8008; | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const run = async () => { | ||
const express = require('express'); | ||
const Dataloader = require('dataloader'); | ||
|
||
const app = express(); | ||
const dataloader = new Dataloader(async keys => keys.map((_, idx) => idx), { | ||
cache: false, | ||
}); | ||
|
||
app.get('/', (req, res) => { | ||
const user = dataloader.load('user-1'); | ||
res.send(user); | ||
}); | ||
|
||
startExpressServerAndSendPortToRunner(app, PORT); | ||
}; | ||
|
||
run(); |
40 changes: 40 additions & 0 deletions
40
dev-packages/node-integration-tests/suites/tracing/dataloader/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('dataloader auto-instrumentation', () => { | ||
afterAll(async () => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
const EXPECTED_TRANSACTION = { | ||
transaction: 'GET /', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'sentry.origin': 'auto.db.otel.dataloader', | ||
'sentry.op': 'cache.get', | ||
}), | ||
description: 'dataloader.load', | ||
origin: 'auto.db.otel.dataloader', | ||
op: 'cache.get', | ||
status: 'ok', | ||
}), | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'sentry.origin': 'auto.db.otel.dataloader', | ||
'sentry.op': 'cache.get', | ||
}), | ||
description: 'dataloader.batch', | ||
origin: 'auto.db.otel.dataloader', | ||
op: 'cache.get', | ||
status: 'ok', | ||
}), | ||
]), | ||
}; | ||
|
||
test('should auto-instrument `dataloader` package.', done => { | ||
createRunner(__dirname, 'scenario.js') | ||
.expect({ transaction: EXPECTED_TRANSACTION }) | ||
.start(done) | ||
.makeRequest('get', '/'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { DataloaderInstrumentation } from '@opentelemetry/instrumentation-dataloader'; | ||
import { | ||
SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
defineIntegration, | ||
spanToJSON, | ||
} from '@sentry/core'; | ||
import type { IntegrationFn } from '@sentry/types'; | ||
import { generateInstrumentOnce } from '../../otel/instrument'; | ||
|
||
const INTEGRATION_NAME = 'Dataloader'; | ||
|
||
export const instrumentDataloader = generateInstrumentOnce(INTEGRATION_NAME, () => new DataloaderInstrumentation({})); | ||
|
||
const _dataloaderIntegration = (() => { | ||
return { | ||
name: INTEGRATION_NAME, | ||
setupOnce() { | ||
instrumentDataloader(); | ||
}, | ||
|
||
setup(client) { | ||
client.on('spanStart', span => { | ||
const spanJSON = spanToJSON(span); | ||
if (spanJSON.description?.startsWith('dataloader')) { | ||
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.dataloader'); | ||
} | ||
|
||
// These are all possible dataloader span descriptions | ||
// Still checking for the future versions | ||
// in case they add support for `clear` and `prime` | ||
if ( | ||
spanJSON.description === 'dataloader.load' || | ||
spanJSON.description === 'dataloader.loadMany' || | ||
spanJSON.description === 'dataloader.batch' | ||
) { | ||
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'cache.get'); | ||
// TODO: We can try adding `key` to the `data` attribute upstream. | ||
// Or alternatively, we can add `requestHook` to the dataloader instrumentation. | ||
} | ||
}); | ||
}, | ||
}; | ||
}) satisfies IntegrationFn; | ||
|
||
/** | ||
* Dataloader integration | ||
* | ||
* Capture tracing data for Dataloader. | ||
*/ | ||
export const dataloaderIntegration = defineIntegration(_dataloaderIntegration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7101,6 +7101,13 @@ | |
"@opentelemetry/semantic-conventions" "^1.27.0" | ||
"@types/connect" "3.4.36" | ||
|
||
"@opentelemetry/[email protected]": | ||
version "0.12.0" | ||
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation-dataloader/-/instrumentation-dataloader-0.12.0.tgz#de03a3948dec4f15fed80aa424d6bd5d6a8d10c7" | ||
integrity sha512-pnPxatoFE0OXIZDQhL2okF//dmbiWFzcSc8pUg9TqofCLYZySSxDCgQc69CJBo5JnI3Gz1KP+mOjS4WAeRIH4g== | ||
dependencies: | ||
"@opentelemetry/instrumentation" "^0.53.0" | ||
|
||
"@opentelemetry/[email protected]": | ||
version "0.42.0" | ||
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation-express/-/instrumentation-express-0.42.0.tgz#279f195aa66baee2b98623a16666c6229c8e7564" | ||
|
@@ -15235,6 +15242,11 @@ data-urls@^4.0.0: | |
whatwg-mimetype "^3.0.0" | ||
whatwg-url "^12.0.0" | ||
|
||
[email protected]: | ||
version "2.2.2" | ||
resolved "https://registry.yarnpkg.com/dataloader/-/dataloader-2.2.2.tgz#216dc509b5abe39d43a9b9d97e6e5e473dfbe3e0" | ||
integrity sha512-8YnDaaf7N3k/q5HnTJVuzSyLETjoZjVmHc4AeKAzOvKHEFQKcn64OKBfzHYtE9zGjctNM7V9I0MfnUVLpi7M5g== | ||
|
||
date-fns@^2.29.2: | ||
version "2.29.3" | ||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should set
requireParentSpan
to betrue
by default, and then expose config to change it accordingly, but I'm open to other opinions.@mydea what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's set
requireParentSpan
to betrue
by default @onurtemizkan. We don't need to expose config for now, we can add that later based on user request.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised it's also
true
by default inDataloaderIntegration
. Still, passedtrue
from our side, and we can expose it later if we need to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sounds reasonable to me, I guess you rarely want this to be a transaction!