Skip to content
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: ParentSpanContext Should be Available on Span/ReadableSpan #5418

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
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,164 @@
exportedSpans = [];
});

<<<<<<< Updated upstream

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 296 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.
const assertPropagationHeaders = async (
response: Response
): Promise<Record<string, string>> => {
const { request } = await response.json();

const span: tracing.ReadableSpan = exportedSpans[0];
=======

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 303 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.
it('should create a span with correct root span', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanContext,
rootSpan.spanContext(),
'parent span is not root span'
);
});

it('span should have correct name', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(span.name, 'HTTP GET', 'span has wrong name');
});

it('span should have correct kind', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(span.kind, api.SpanKind.CLIENT, 'span has wrong kind');
});

it('span should have correct attributes', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
const attributes = span.attributes;
const keys = Object.keys(attributes);
assert.notStrictEqual(
attributes[AttributeNames.COMPONENT],
'',
`attributes ${AttributeNames.COMPONENT} is not defined`
);

assert.strictEqual(
attributes[SEMATTRS_HTTP_METHOD],
'GET',
`attributes ${SEMATTRS_HTTP_METHOD} is wrong`
);
assert.strictEqual(
attributes[SEMATTRS_HTTP_URL],
url,
`attributes ${SEMATTRS_HTTP_URL} is wrong`
);
assert.strictEqual(
attributes[SEMATTRS_HTTP_STATUS_CODE],
200,
`attributes ${SEMATTRS_HTTP_STATUS_CODE} is wrong`
);
const statusText = attributes[AttributeNames.HTTP_STATUS_TEXT];
assert.ok(
statusText === 'OK' || statusText === '',
`attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong`
);
assert.ok(
(attributes[SEMATTRS_HTTP_HOST] as string).indexOf('localhost') === 0,
`attributes ${SEMATTRS_HTTP_HOST} is wrong`
);

const httpScheme = attributes[SEMATTRS_HTTP_SCHEME];
assert.ok(
httpScheme === 'http' || httpScheme === 'https',
`attributes ${SEMATTRS_HTTP_SCHEME} is wrong`
);
assert.notStrictEqual(
attributes[SEMATTRS_HTTP_USER_AGENT],
'',
`attributes ${SEMATTRS_HTTP_USER_AGENT} is not defined`
);
const requestContentLength = attributes[
SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED
] as number;
assert.strictEqual(
requestContentLength,
undefined,
`attributes ${SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED} is defined`
);
const responseContentLength = attributes[
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH
] as number;
assert.strictEqual(
responseContentLength,
30,
`attributes ${SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH} is <= 0`
);

assert.strictEqual(keys.length, 9, 'number of attributes is wrong');
});

it('span should have correct events', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
const events = span.events;
assert.strictEqual(events.length, 8, 'number of events is wrong');
testForCorrectEvents(events, [
PTN.FETCH_START,
PTN.DOMAIN_LOOKUP_START,
PTN.DOMAIN_LOOKUP_END,
PTN.CONNECT_START,
PTN.CONNECT_END,
PTN.REQUEST_START,
PTN.RESPONSE_START,
PTN.RESPONSE_END,
]);
});

it('should create a span for preflight request', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
const parentSpan: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanContext,
parentSpan.spanContext(),
'parent span is not root span'
);
});

it('preflight request span should have correct name', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
assert.strictEqual(
span.name,
'CORS Preflight',
'preflight request span has wrong name'
);
});

it('preflight request span should have correct kind', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
assert.strictEqual(
span.kind,
api.SpanKind.INTERNAL,
'span has wrong kind'
);
});

it('preflight request span should have correct events', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
const events = span.events;
assert.strictEqual(events.length, 8, 'number of events is wrong');
testForCorrectEvents(events, [
PTN.FETCH_START,
PTN.DOMAIN_LOOKUP_START,
PTN.DOMAIN_LOOKUP_END,
PTN.CONNECT_START,
PTN.CONNECT_END,
PTN.REQUEST_START,
PTN.RESPONSE_START,
PTN.RESPONSE_END,
]);
});

it('should set trace headers', async () => {
const span: api.Span = exportSpy.args[1][0][0];
assert.ok(lastResponse instanceof Response);

const { request } = await lastResponse.json();
>>>>>>> Stashed changes

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 453 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.

assert.strictEqual(
request.headers[X_B3_TRACE_ID],
Expand Down Expand Up @@ -1156,6 +1308,21 @@
});
});
});
<<<<<<< Updated upstream

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 1311 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.
=======

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 1312 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.
afterEach(() => {
clearData();
});
it('should create a span with correct root span', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanContext,
rootSpan.spanContext(),
'parent span is not root span'
);
});
});
>>>>>>> Stashed changes

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 1325 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.

describe('secure origin requests', () => {
const tracedFetch = async ({
Expand Down Expand Up @@ -1208,11 +1375,23 @@
});
});

<<<<<<< Updated upstream

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 1378 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.
describe('`applyCustomAttributesOnSpan` hook', () => {
const tracedFetch = async ({
handlers = [
msw.http.get('/api/project-headers.json', ({ request }) => {
const headers = new Headers();
=======

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 1384 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.
it('should create a span with correct root span', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanContext,
rootSpan.spanContext(),
'parent span is not root span'
);
});
});
>>>>>>> Stashed changes

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20.6.0)

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (22)

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18.19.0)

Merge conflict marker encountered.

Check failure on line 1394 in experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Merge conflict marker encountered.

for (const [key, value] of request.headers) {
headers.set(`x-request-${key}`, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ export const assertSpan = (
validations.component,
' must have http.scheme attribute'
);
assert.ok(typeof span.parentSpanId === 'string');
assert.ok(isValidSpanId(span.parentSpanId));
assert.ok(typeof span.parentSpanContext?.spanId === 'string');
assert.ok(isValidSpanId(span.parentSpanContext.spanId));
} else if (validations.reqHeaders) {
assert.ok(validations.reqHeaders[DummyPropagation.TRACE_CONTEXT_KEY]);
assert.ok(validations.reqHeaders[DummyPropagation.SPAN_CONTEXT_KEY]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('xhr', () => {
it('should create a span with correct root span', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanId,
span.parentSpanContext?.spanId,
rootSpan.spanContext().spanId,
'parent span is not root span'
);
Expand Down Expand Up @@ -489,7 +489,7 @@ describe('xhr', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
const parentSpan: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanId,
span.parentSpanContext?.spanId,
parentSpan.spanContext().spanId,
'parent span is not root span'
);
Expand Down Expand Up @@ -1583,7 +1583,7 @@ describe('xhr', () => {
it('should create a span with correct root span', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanId,
span.parentSpanContext?.spanId,
rootSpan.spanContext().spanId,
'parent span is not root span'
);
Expand Down Expand Up @@ -1687,7 +1687,7 @@ describe('xhr', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
const parentSpan: tracing.ReadableSpan = exportSpy.args[1][0][0];
assert.strictEqual(
span.parentSpanId,
span.parentSpanContext?.spanId,
parentSpan.spanContext().spanId,
'parent span is not root span'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { SpanContext } from '@opentelemetry/api';
import {
Fixed64,
IInstrumentationScope,
Expand Down Expand Up @@ -65,6 +66,9 @@ export interface ISpan {
/** Span parentSpanId */
parentSpanId?: string | Uint8Array;

/** Span parentSpanContext */
parentSpanContext?: SpanContext;

/** Span name */
name: string;

Expand Down
4 changes: 2 additions & 2 deletions experimental/packages/otlp-transformer/test/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('Trace', () => {
});
assert.ok(exportRequest);
assert.strictEqual(
exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanId,
exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanContext?.spanId,
undefined
);
});
Expand All @@ -348,7 +348,7 @@ describe('Trace', () => {
});
assert.ok(exportRequest);
assert.strictEqual(
exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanId,
exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanContext?.spanId,
undefined
);
});
Expand Down
10 changes: 9 additions & 1 deletion experimental/packages/shim-opencensus/src/ShimSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as oc from '@opencensus/core';
import { ShimTracer } from './ShimTracer';
import { AttributeValue, Span, SpanStatusCode, diag } from '@opentelemetry/api';
import { AttributeValue, Span, SpanContext, SpanStatusCode, diag } from '@opentelemetry/api';
import { mapMessageEvent, reverseMapSpanContext } from './trace-transform';

// Copied from
Expand All @@ -33,6 +33,7 @@ interface Options {
isRootSpan?: boolean | undefined;
kind?: oc.SpanKind | undefined;
parentSpanId?: string | undefined;
parentSpanContext?: SpanContext;
}

export class ShimSpan implements oc.Span {
Expand Down Expand Up @@ -71,6 +72,7 @@ export class ShimSpan implements oc.Span {

readonly kind: oc.SpanKind;
readonly parentSpanId: string;
readonly parentSpanContext: SpanContext;

get remoteParent(): boolean {
return this.otelSpan.spanContext().isRemote ?? false;
Expand All @@ -83,12 +85,18 @@ export class ShimSpan implements oc.Span {
isRootSpan = false,
kind = oc.SpanKind.UNSPECIFIED,
parentSpanId = '',
parentSpanContext = {
spanId: '',
traceId: '',
traceFlags: 0,
},
}: Options) {
this._shimTracer = shimTracer;
this.otelSpan = otelSpan;
this._isRootSpan = isRootSpan;
this.kind = kind;
this.parentSpanId = parentSpanId;
this.parentSpanContext = parentSpanContext;
}

/** Returns whether a span is root or not. */
Expand Down
2 changes: 2 additions & 0 deletions experimental/packages/shim-opencensus/src/ShimTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class ShimTracer implements oc.Tracer {
isRootSpan: true,
kind,
parentSpanId: trace.getSpanContext(parentCtx)?.spanId,
parentSpanContext: trace.getSpanContext(parentCtx),
});

let ctx = trace.setSpan(parentCtx, otelSpan);
Expand Down Expand Up @@ -148,6 +149,7 @@ export class ShimTracer implements oc.Tracer {
isRootSpan: false,
kind,
parentSpanId: trace.getSpanContext(ctx)?.spanId,
parentSpanContext: trace.getSpanContext(ctx),
});
}

Expand Down
4 changes: 2 additions & 2 deletions experimental/packages/shim-opencensus/test/ShimSpan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('ShimSpan', () => {

assert.strictEqual(childSpan.name, 'span');
assert.deepStrictEqual(
childSpan.parentSpanId,
childSpan.parentSpanContext?.spanId,
parentSpan.spanContext().spanId
);
});
Expand All @@ -120,7 +120,7 @@ describe('ShimSpan', () => {

assert.strictEqual(childSpan.name, 'child');
assert.deepStrictEqual(
childSpan.parentSpanId,
childSpan.parentSpanContext?.spanId,
parentSpan.spanContext().spanId
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('ShimTracer', () => {
otelSpans[0].spanContext().traceId,
'9e7ecdc193765065fee1efe757fdd874'
);
assert.strictEqual(otelSpans[0].parentSpanId, '4bf6239d37d8b0f0');
assert.strictEqual(otelSpans[0].parentSpanContext?.spanId, '4bf6239d37d8b0f0');
});

it('should set the span as root span in context', async () => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('ShimTracer', () => {
parent.end();
});
assert.strictEqual(
childSpan.parentSpanId,
childSpan.parentSpanContext?.spanId,
parentSpan.spanContext().spanId
);
});
Expand All @@ -171,7 +171,7 @@ describe('ShimTracer', () => {
}
);
});
assert.strictEqual(childSpan.parentSpanId, rootSpan.spanContext().spanId);
assert.strictEqual(childSpan.parentSpanContext?.spanId, rootSpan.spanContext().spanId);
});
});

Expand Down
Loading
Loading