-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tracemetrics): Add trace metrics behind an experiments flag #17883
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
Open
k-fish
wants to merge
15
commits into
develop
Choose a base branch
from
feat/tracemetrics/add-experimental-metrics
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,799
−7
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4a476a2
feat(tracemetrics): Add trace metrics behind an experiments flag
k-fish 1650fbd
Merge remote-tracking branch 'origin/master' into feat/tracemetrics/a…
k-fish b36ed06
Merge branch 'develop' into feat/tracemetrics/add-experimental-metrics
chargome ab95d3f
use _experiments
chargome 90ca147
update test
chargome 9cb8442
update debug log
chargome ee8c08f
update replayId attaching logic
chargome cb2102b
bump size limit
chargome 0929feb
add unit tests
chargome 350567f
.
chargome caa59ea
filter browser session integration to unflake test
chargome b36d517
export from node-core
chargome dac2aca
add node integration tests
chargome 8e12b0d
ignore node exports for now
chargome 0d7323c
We changed envelope to 'trace_metric' to avoid ambiguity
k-fish 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
There are no files selected for viewing
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
dev-packages/browser-integration-tests/suites/public-api/metrics/init.js
This file contains hidden or 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,15 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
_experiments: { | ||
enableTraceMetrics: true, | ||
}, | ||
release: '1.0.0', | ||
environment: 'test', | ||
integrations: integrations => { | ||
return integrations.filter(integration => integration.name !== 'BrowserSession'); | ||
}, | ||
}); |
12 changes: 12 additions & 0 deletions
12
dev-packages/browser-integration-tests/suites/public-api/metrics/simple/subject.js
This file contains hidden or 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,12 @@ | ||
Sentry.metrics.count('test.counter', 1, { attributes: { endpoint: '/api/test' } }); | ||
Sentry.metrics.gauge('test.gauge', 42, { unit: 'millisecond', attributes: { server: 'test-1' } }); | ||
Sentry.metrics.distribution('test.distribution', 200, { unit: 'second', attributes: { priority: 'high' } }); | ||
|
||
Sentry.startSpan({ name: 'test-span', op: 'test' }, () => { | ||
Sentry.metrics.count('test.span.counter', 1, { attributes: { operation: 'test' } }); | ||
}); | ||
|
||
Sentry.setUser({ id: 'user-123', email: '[email protected]', username: 'testuser' }); | ||
Sentry.metrics.count('test.user.counter', 1, { attributes: { action: 'click' } }); | ||
|
||
Sentry.flush(); |
104 changes: 104 additions & 0 deletions
104
dev-packages/browser-integration-tests/suites/public-api/metrics/simple/test.ts
This file contains hidden or 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,104 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { MetricEnvelope } from '@sentry/core'; | ||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest, properFullEnvelopeRequestParser } from '../../../../utils/helpers'; | ||
|
||
sentryTest('should capture all metric types', async ({ getLocalTestUrl, page }) => { | ||
const bundle = process.env.PW_BUNDLE || ''; | ||
if (bundle.startsWith('bundle') || bundle.startsWith('loader')) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const event = await getFirstSentryEnvelopeRequest<MetricEnvelope>(page, url, properFullEnvelopeRequestParser); | ||
const envelopeItems = event[1]; | ||
|
||
expect(envelopeItems[0]).toEqual([ | ||
{ | ||
type: 'trace_metric', | ||
item_count: 5, | ||
content_type: 'application/vnd.sentry.items.trace-metric+json', | ||
}, | ||
{ | ||
items: [ | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.counter', | ||
type: 'counter', | ||
value: 1, | ||
attributes: { | ||
endpoint: { value: '/api/test', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.gauge', | ||
type: 'gauge', | ||
unit: 'millisecond', | ||
value: 42, | ||
attributes: { | ||
server: { value: 'test-1', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.distribution', | ||
type: 'distribution', | ||
unit: 'second', | ||
value: 200, | ||
attributes: { | ||
priority: { value: 'high', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
span_id: expect.any(String), | ||
name: 'test.span.counter', | ||
type: 'counter', | ||
value: 1, | ||
attributes: { | ||
operation: { value: 'test', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.user.counter', | ||
type: 'counter', | ||
value: 1, | ||
attributes: { | ||
action: { value: 'click', type: 'string' }, | ||
'user.id': { value: 'user-123', type: 'string' }, | ||
'user.email': { value: '[email protected]', type: 'string' }, | ||
'user.name': { value: 'testuser', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.browser', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
}); |
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
dev-packages/node-core-integration-tests/suites/public-api/metrics/scenario.ts
This file contains hidden or 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,35 @@ | ||
import * as Sentry from '@sentry/node-core'; | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import { setupOtel } from '../../../utils/setupOtel'; | ||
|
||
const client = Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0.0', | ||
environment: 'test', | ||
_experiments: { | ||
enableTraceMetrics: true, | ||
}, | ||
transport: loggingTransport, | ||
}); | ||
|
||
setupOtel(client); | ||
|
||
async function run(): Promise<void> { | ||
Sentry.metrics.count('test.counter', 1, { attributes: { endpoint: '/api/test' } }); | ||
|
||
Sentry.metrics.gauge('test.gauge', 42, { unit: 'millisecond', attributes: { server: 'test-1' } }); | ||
|
||
Sentry.metrics.distribution('test.distribution', 200, { unit: 'second', attributes: { priority: 'high' } }); | ||
|
||
await Sentry.startSpan({ name: 'test-span', op: 'test' }, async () => { | ||
Sentry.metrics.count('test.span.counter', 1, { attributes: { operation: 'test' } }); | ||
}); | ||
|
||
Sentry.setUser({ id: 'user-123', email: '[email protected]', username: 'testuser' }); | ||
Sentry.metrics.count('test.user.counter', 1, { attributes: { action: 'click' } }); | ||
|
||
await Sentry.flush(); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
void run(); |
97 changes: 97 additions & 0 deletions
97
dev-packages/node-core-integration-tests/suites/public-api/metrics/test.ts
This file contains hidden or 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,97 @@ | ||
import { afterAll, describe, expect, test } from 'vitest'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('metrics', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should capture all metric types', async () => { | ||
const runner = createRunner(__dirname, 'scenario.ts') | ||
.unignore('metric') | ||
.expect({ | ||
metric: { | ||
items: [ | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.counter', | ||
type: 'counter', | ||
value: 1, | ||
attributes: { | ||
endpoint: { value: '/api/test', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.gauge', | ||
type: 'gauge', | ||
unit: 'millisecond', | ||
value: 42, | ||
attributes: { | ||
server: { value: 'test-1', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.distribution', | ||
type: 'distribution', | ||
unit: 'second', | ||
value: 200, | ||
attributes: { | ||
priority: { value: 'high', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.span.counter', | ||
type: 'counter', | ||
value: 1, | ||
attributes: { | ||
operation: { value: 'test', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
timestamp: expect.any(Number), | ||
trace_id: expect.any(String), | ||
name: 'test.user.counter', | ||
type: 'counter', | ||
value: 1, | ||
attributes: { | ||
action: { value: 'click', type: 'string' }, | ||
'user.id': { value: 'user-123', type: 'string' }, | ||
'user.email': { value: '[email protected]', type: 'string' }, | ||
'user.name': { value: 'testuser', type: 'string' }, | ||
'sentry.release': { value: '1.0.0', type: 'string' }, | ||
'sentry.environment': { value: 'test', type: 'string' }, | ||
'sentry.sdk.name': { value: 'sentry.javascript.node-core', type: 'string' }, | ||
'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
.start(); | ||
|
||
await runner.completed(); | ||
}); | ||
}); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.