Skip to content

feat(replays): add replay_id to dynamic sampling context #7493

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
TransactionMetadata,
} from '@sentry/types';
import { dropUndefinedKeys, logger } from '@sentry/utils';
import { Replay } from '@sentry/replay';

import { DEFAULT_ENVIRONMENT } from '../constants';
import type { Hub } from '../hub';
Expand Down Expand Up @@ -241,6 +242,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
* @experimental
*/
public getDynamicSamplingContext(): Readonly<Partial<DynamicSamplingContext>> {
console.log('dsc');
if (this._frozenDynamicSamplingContext) {
return this._frozenDynamicSamplingContext;
}
Expand All @@ -261,6 +263,12 @@ export class Transaction extends SpanClass implements TransactionInterface {

const source = this.metadata.source;

const replay = client.getIntegration(Replay);
let replay_id;
if (replay) {
replay_id = replay.getCurrentReplayId();
}

// We don't want to have a transaction name in the DSC if the source is "url" because URLs might contain PII
const transaction = source && source !== 'url' ? this.name : undefined;

Expand All @@ -272,6 +280,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
public_key,
trace_id: this.traceId,
sample_rate,
replay_id,
});

// Uncomment if we want to make DSC immutable
Expand Down
8 changes: 8 additions & 0 deletions packages/replay/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
return this._replay.flushImmediate();
}

/** returns the current replayId if there is an existing session */
public getCurrentReplayId(): string | undefined {
if (!this._replay || !this._replay.session) {
return;
}
return this._replay.session.id;
}

/** Setup the integration. */
private _setup(): void {
// Client is not available in constructor, so we need to wait until setupOnce
Expand Down
2 changes: 2 additions & 0 deletions packages/tracing/src/browser/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export function fetchCallback(
shouldAttachHeaders: (url: string) => boolean,
spans: Record<string, Span>,
): void {
console.log(2);
if (!hasTracingEnabled() || !(handlerData.fetchData && shouldCreateSpan(handlerData.fetchData.url))) {
return;
}
Expand Down Expand Up @@ -294,6 +295,7 @@ export function xhrCallback(
shouldAttachHeaders: (url: string) => boolean,
spans: Record<string, Span>,
): void {
console.log(1);
if (
!hasTracingEnabled() ||
(handlerData.xhr && handlerData.xhr.__sentry_own_request__) ||
Expand Down