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

fix: include TraceState in trace exports #3569

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
* fix: avoid grpc types dependency [#3551](https://github.com/open-telemetry/opentelemetry-js/pull/3551) @flarna
* fix(otlp-proto-exporter-base): Match Accept header with Content-Type in the proto exporter
[#3562](https://github.com/open-telemetry/opentelemetry-js/pull/3562) @scheler
* fix: include tracestate in export [#3569](https://github.com/open-telemetry/opentelemetry-js/pull/3569) @flarna

### :books: (Refine Doc)

Expand Down
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix: include tracestate in export [#3569](https://github.com/open-telemetry/opentelemetry-js/pull/3569) @flarna

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function sdkSpanToOtlpSpan(span: ReadableSpan, useHex?: boolean): ISpan {
traceId: useHex ? ctx.traceId : core.hexToBase64(ctx.traceId),
spanId: useHex ? ctx.spanId : core.hexToBase64(ctx.spanId),
parentSpanId: parentSpanId,
traceState: ctx.traceState?.serialize(),
name: span.name,
// Span kind is offset by 1 because the API does not define a value for unset
kind: span.kind == null ? 0 : span.kind + 1,
Expand Down Expand Up @@ -60,6 +61,7 @@ export function toOtlpLink(link: Link, useHex?: boolean): ILink {
traceId: useHex
? link.context.traceId
: core.hexToBase64(link.context.traceId),
traceState: link.context.traceState?.serialize(),
droppedAttributesCount: 0,
};
}
Expand Down
6 changes: 4 additions & 2 deletions experimental/packages/otlp-transformer/test/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ function createExpectedSpanJson(useHex: boolean) {
traceId: traceId,
spanId: spanId,
parentSpanId: parentSpanId,
traceState: 'span=bar',
name: 'span-name',
kind: ESpanKind.SPAN_KIND_CLIENT,
links: [
{
droppedAttributesCount: 0,
spanId: linkSpanId,
traceId: linkTraceId,
traceState: 'link=foo',
attributes: [
{
key: 'link-attribute',
Expand Down Expand Up @@ -134,7 +136,7 @@ describe('Trace', () => {
traceFlags: 1,
traceId: '00000000000000000000000000000001',
isRemote: false,
traceState: new TraceState(''),
traceState: new TraceState('span=bar'),
}),
parentSpanId: '0000000000000001',
attributes: { 'string-attribute': 'some attribute value' },
Expand Down Expand Up @@ -163,7 +165,7 @@ describe('Trace', () => {
traceId: '00000000000000000000000000000002',
traceFlags: 1,
isRemote: false,
traceState: new TraceState(''),
traceState: new TraceState('link=foo'),
},
attributes: {
'link-attribute': 'string value',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class ConsoleSpanExporter implements SpanExporter {
return {
traceId: span.spanContext().traceId,
parentId: span.parentSpanId,
traceState: span.spanContext().traceState?.serialize(),
name: span.name,
id: span.spanContext().spanId,
kind: span.kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { SpanContext, TraceFlags } from '@opentelemetry/api';
import { TraceState } from '@opentelemetry/core';
import * as assert from 'assert';
import * as sinon from 'sinon';
import {
Expand Down Expand Up @@ -63,6 +64,7 @@ describe('ConsoleSpanExporter', () => {
const span = tracer.startSpan('foo', {
links: [{ context, attributes: { anAttr: 'aValue' } }],
});
span.spanContext().traceState = new TraceState('trace=state');
span.addEvent('foobar');
span.end();

Expand All @@ -85,6 +87,7 @@ describe('ConsoleSpanExporter', () => {
'status',
'timestamp',
'traceId',
'traceState',
].join(',');

assert.ok(firstSpan.name === 'foo');
Expand Down