Skip to content
Merged
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
7 changes: 5 additions & 2 deletions packages/core/jest/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module.exports = {
stopResource: jest
.fn()
.mockImplementation(() => new Promise(resolve => resolve())),
generateUUID: jest.fn().mockImplementation(() => 'fakeUUID'),
addError: jest
.fn()
.mockImplementation(() => new Promise(resolve => resolve())),
Expand All @@ -117,7 +116,11 @@ module.exports = {
() => new Promise(resolve => resolve('test-session-id'))
),
setTimeProvider: jest.fn().mockImplementation(() => {}),
timeProvider: jest.fn().mockReturnValue(undefined)
timeProvider: jest.fn().mockReturnValue(undefined),
getTracingContext: jest.fn().mockReturnValue(undefined),
getTracingContextForPropagators: jest.fn().mockReturnValue(undefined),
generateTraceId: jest.fn().mockReturnValue('mock-trace-id'),
generateSpanId: jest.fn().mockReturnValue('mock-span-id')
},

DatadogProvider: DatadogProviderMock
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ import { DdTrace } from './trace/DdTrace';
import { DefaultTimeProvider } from './utils/time-provider/DefaultTimeProvider';
import { TimeProvider } from './utils/time-provider/TimeProvider';
import type { Timestamp } from './utils/time-provider/TimeProvider';
import { TracingIdType } from './rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
import {
TracingIdType,
TracingIdFormat
} from './rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
import { DatadogTracingIdentifier } from './rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier';
import { DatadogTracingContext } from './rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext';

/* eslint-enable arca/import-ordering */

Expand Down Expand Up @@ -66,7 +71,10 @@ export {
DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
DATADOG_GRAPH_QL_VARIABLES_HEADER,
TracingIdType
TracingIdType,
TracingIdFormat,
DatadogTracingIdentifier,
DatadogTracingContext
};

export type { Timestamp };
66 changes: 38 additions & 28 deletions packages/core/src/rum/DdRum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider'
import type { TimeProvider } from '../utils/time-provider/TimeProvider';

import { DdAttributes } from './DdAttributes';
import type { ActionEventMapper } from './eventMappers/actionEventMapper';
import { generateActionEventMapper } from './eventMappers/actionEventMapper';
import type { ErrorEventMapper } from './eventMappers/errorEventMapper';
import type { ActionEventMapper } from './eventMappers/actionEventMapper';
import { generateErrorEventMapper } from './eventMappers/errorEventMapper';
import type { ResourceEventMapper } from './eventMappers/resourceEventMapper';
import type { ErrorEventMapper } from './eventMappers/errorEventMapper';
import { generateResourceEventMapper } from './eventMappers/resourceEventMapper';
import type { ResourceEventMapper } from './eventMappers/resourceEventMapper';
import type { DatadogTracingContext } from './instrumentation/resourceTracking/distributedTracing/DatadogTracingContext';
import { DatadogTracingIdentifier } from './instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier';
import { TracingIdentifier } from './instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
import {
TracingIdFormat,
TracingIdType,
TracingIdentifier
} from './instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
getTracingContext,
getTracingContextForPropagators
} from './instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders';
import type {
ErrorSource,
DdRumType,
RumActionType,
ResourceKind
ResourceKind,
FirstPartyHost,
PropagatorType
} from './types';

const generateEmptyPromise = () => new Promise<void>(resolve => resolve());
Expand Down Expand Up @@ -230,26 +234,6 @@ class DdRumWrapper implements DdRumType {
);
};

generateUUID = (type: TracingIdType): string => {
switch (type) {
case TracingIdType.trace:
return TracingIdentifier.createTraceId().toString(
TracingIdFormat.paddedHex
);
case TracingIdType.span:
return TracingIdentifier.createSpanId().toString(
TracingIdFormat.decimal
);
default:
console.warn(
`Unsupported tracing ID type '${type}' for generateUUID. Falling back to 64 bit Span ID.`
);
return TracingIdentifier.createSpanId().toString(
TracingIdFormat.decimal
);
}
};

addError = (
message: string,
source: ErrorSource,
Expand Down Expand Up @@ -320,6 +304,32 @@ class DdRumWrapper implements DdRumType {
return this.nativeRum.getCurrentSessionId();
}

getTracingContext = (
url: string,
tracingSamplingRate: number,
firstPartyHosts: FirstPartyHost[]
): DatadogTracingContext => {
return getTracingContext(url, tracingSamplingRate, firstPartyHosts);
};

getTracingContextForPropagators = (
propagators: PropagatorType[],
tracingSamplingRate: number
): DatadogTracingContext => {
return getTracingContextForPropagators(
propagators,
tracingSamplingRate
);
};

generateTraceId(): DatadogTracingIdentifier {
return new DatadogTracingIdentifier(TracingIdentifier.createTraceId());
}

generateSpanId(): DatadogTracingIdentifier {
return new DatadogTracingIdentifier(TracingIdentifier.createSpanId());
}

registerErrorEventMapper(errorEventMapper: ErrorEventMapper) {
this.errorEventMapper = generateErrorEventMapper(errorEventMapper);
}
Expand Down
Loading
Loading