From 8b8d4967c1bfbc0c2e0d76ade16436222c3217ec Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Tue, 4 May 2021 21:48:12 +0200 Subject: [PATCH 1/3] chore: removing usage of timed event from api --- .../src/transform.ts | 2 +- .../src/types.ts | 19 +++++++++++- .../src/transform.ts | 3 +- .../src/types.ts | 13 +++++++++ packages/opentelemetry-tracing/src/Span.ts | 3 +- .../opentelemetry-tracing/src/TimedEvent.ts | 29 +++++++++++++++++++ .../src/export/ReadableSpan.ts | 2 +- packages/opentelemetry-tracing/src/index.ts | 1 + 8 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 packages/opentelemetry-tracing/src/TimedEvent.ts diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index 7080713ff7..47676d9c64 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -19,7 +19,6 @@ import { Link, SpanKind, SpanStatus, - TimedEvent, TraceState, } from '@opentelemetry/api'; import * as core from '@opentelemetry/core'; @@ -30,6 +29,7 @@ import { COLLECTOR_SPAN_KIND_MAPPING, opentelemetryProto, CollectorExporterConfigBase, + TimedEvent, } from './types'; const MAX_INTEGER_VALUE = 2147483647; diff --git a/packages/opentelemetry-exporter-collector/src/types.ts b/packages/opentelemetry-exporter-collector/src/types.ts index f0b02825f3..ad19549952 100644 --- a/packages/opentelemetry-exporter-collector/src/types.ts +++ b/packages/opentelemetry-exporter-collector/src/types.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { SpanAttributes, SpanKind, SpanStatusCode } from '@opentelemetry/api'; +import { + HrTime, + SpanAttributes, + SpanKind, + SpanStatusCode, +} from '@opentelemetry/api'; /* eslint-disable @typescript-eslint/no-namespace */ /* eslint-disable @typescript-eslint/no-unused-vars */ @@ -362,3 +367,15 @@ export const COLLECTOR_SPAN_KIND_MAPPING = { [SpanKind.CONSUMER]: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_CONSUMER, }; + +/** + * Represents a timed event. + * A timed event is an event with a timestamp. + */ +export interface TimedEvent { + time: HrTime; + /** The name of the event. */ + name: string; + /** The attributes of the event. */ + attributes?: SpanAttributes; +} diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index 032227716f..0bad3b6fe1 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -17,6 +17,7 @@ import * as api from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/tracing'; import { hrTimeToMicroseconds } from '@opentelemetry/core'; +import { TimedEvent } from './types'; import * as zipkinTypes from './types'; import { Resource } from '@opentelemetry/resources'; @@ -94,7 +95,7 @@ export function _toZipkinTags( * Converts OpenTelemetry Events to Zipkin Annotations format. */ export function _toZipkinAnnotations( - events: api.TimedEvent[] + events: TimedEvent[] ): zipkinTypes.Annotation[] { return events.map(event => ({ timestamp: hrTimeToMicroseconds(event.time), diff --git a/packages/opentelemetry-exporter-zipkin/src/types.ts b/packages/opentelemetry-exporter-zipkin/src/types.ts index f419c65f08..ba61a81b51 100644 --- a/packages/opentelemetry-exporter-zipkin/src/types.ts +++ b/packages/opentelemetry-exporter-zipkin/src/types.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { HrTime, SpanAttributes } from '@opentelemetry/api'; import { ExportResult } from '@opentelemetry/core'; /** @@ -187,3 +188,15 @@ export type SendFunction = ( ) => void; export type GetHeaders = () => Record | undefined; + +/** + * Represents a timed event. + * A timed event is an event with a timestamp. + */ +export interface TimedEvent { + time: HrTime; + /** The name of the event. */ + name: string; + /** The attributes of the event. */ + attributes?: SpanAttributes; +} diff --git a/packages/opentelemetry-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index bfaf77b20b..79ab92544a 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -26,6 +26,7 @@ import { import { Resource } from '@opentelemetry/resources'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { ReadableSpan } from './export/ReadableSpan'; +import { TimedEvent } from './TimedEvent'; import { Tracer } from './Tracer'; import { SpanProcessor } from './SpanProcessor'; import { TraceParams } from './types'; @@ -43,7 +44,7 @@ export class Span implements api.Span, ReadableSpan { readonly parentSpanId?: string; readonly attributes: api.SpanAttributes = {}; readonly links: api.Link[] = []; - readonly events: api.TimedEvent[] = []; + readonly events: TimedEvent[] = []; readonly startTime: api.HrTime; readonly resource: Resource; readonly instrumentationLibrary: InstrumentationLibrary; diff --git a/packages/opentelemetry-tracing/src/TimedEvent.ts b/packages/opentelemetry-tracing/src/TimedEvent.ts new file mode 100644 index 0000000000..93cb9b47f3 --- /dev/null +++ b/packages/opentelemetry-tracing/src/TimedEvent.ts @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { HrTime, SpanAttributes } from '@opentelemetry/api'; + +/** + * Represents a timed event. + * A timed event is an event with a timestamp. + */ +export interface TimedEvent { + time: HrTime; + /** The name of the event. */ + name: string; + /** The attributes of the event. */ + attributes?: SpanAttributes; +} diff --git a/packages/opentelemetry-tracing/src/export/ReadableSpan.ts b/packages/opentelemetry-tracing/src/export/ReadableSpan.ts index 9813965b0c..381de674ff 100644 --- a/packages/opentelemetry-tracing/src/export/ReadableSpan.ts +++ b/packages/opentelemetry-tracing/src/export/ReadableSpan.ts @@ -21,10 +21,10 @@ import { HrTime, Link, SpanContext, - TimedEvent, } from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import { InstrumentationLibrary } from '@opentelemetry/core'; +import { TimedEvent } from '../TimedEvent'; export interface ReadableSpan { readonly name: string; diff --git a/packages/opentelemetry-tracing/src/index.ts b/packages/opentelemetry-tracing/src/index.ts index 720241a310..188b5105ce 100644 --- a/packages/opentelemetry-tracing/src/index.ts +++ b/packages/opentelemetry-tracing/src/index.ts @@ -24,4 +24,5 @@ export * from './export/SimpleSpanProcessor'; export * from './export/SpanExporter'; export * from './Span'; export * from './SpanProcessor'; +export * from './TimedEvent'; export * from './types'; From 07b71f5b51e32bd9f30c460cd2c7fb671c953c8b Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 6 May 2021 20:49:13 +0200 Subject: [PATCH 2/3] chore: reviews --- .../opentelemetry-exporter-zipkin/src/transform.ts | 3 +-- packages/opentelemetry-exporter-zipkin/src/types.ts | 13 ------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index 0bad3b6fe1..4f8e3145c6 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -15,9 +15,8 @@ */ import * as api from '@opentelemetry/api'; -import { ReadableSpan } from '@opentelemetry/tracing'; +import { ReadableSpan, TimedEvent } from '@opentelemetry/tracing'; import { hrTimeToMicroseconds } from '@opentelemetry/core'; -import { TimedEvent } from './types'; import * as zipkinTypes from './types'; import { Resource } from '@opentelemetry/resources'; diff --git a/packages/opentelemetry-exporter-zipkin/src/types.ts b/packages/opentelemetry-exporter-zipkin/src/types.ts index ba61a81b51..f419c65f08 100644 --- a/packages/opentelemetry-exporter-zipkin/src/types.ts +++ b/packages/opentelemetry-exporter-zipkin/src/types.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { HrTime, SpanAttributes } from '@opentelemetry/api'; import { ExportResult } from '@opentelemetry/core'; /** @@ -188,15 +187,3 @@ export type SendFunction = ( ) => void; export type GetHeaders = () => Record | undefined; - -/** - * Represents a timed event. - * A timed event is an event with a timestamp. - */ -export interface TimedEvent { - time: HrTime; - /** The name of the event. */ - name: string; - /** The attributes of the event. */ - attributes?: SpanAttributes; -} From b1f810788ff5c2433320ce74df295017cdbbe978 Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 6 May 2021 20:53:45 +0200 Subject: [PATCH 3/3] chore: reviews --- .../src/transform.ts | 3 +-- .../src/types.ts | 19 +------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index 47676d9c64..ee62762159 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -23,13 +23,12 @@ import { } from '@opentelemetry/api'; import * as core from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { ReadableSpan } from '@opentelemetry/tracing'; +import { ReadableSpan, TimedEvent } from '@opentelemetry/tracing'; import { CollectorExporterBase } from './CollectorExporterBase'; import { COLLECTOR_SPAN_KIND_MAPPING, opentelemetryProto, CollectorExporterConfigBase, - TimedEvent, } from './types'; const MAX_INTEGER_VALUE = 2147483647; diff --git a/packages/opentelemetry-exporter-collector/src/types.ts b/packages/opentelemetry-exporter-collector/src/types.ts index ad19549952..f0b02825f3 100644 --- a/packages/opentelemetry-exporter-collector/src/types.ts +++ b/packages/opentelemetry-exporter-collector/src/types.ts @@ -14,12 +14,7 @@ * limitations under the License. */ -import { - HrTime, - SpanAttributes, - SpanKind, - SpanStatusCode, -} from '@opentelemetry/api'; +import { SpanAttributes, SpanKind, SpanStatusCode } from '@opentelemetry/api'; /* eslint-disable @typescript-eslint/no-namespace */ /* eslint-disable @typescript-eslint/no-unused-vars */ @@ -367,15 +362,3 @@ export const COLLECTOR_SPAN_KIND_MAPPING = { [SpanKind.CONSUMER]: opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_CONSUMER, }; - -/** - * Represents a timed event. - * A timed event is an event with a timestamp. - */ -export interface TimedEvent { - time: HrTime; - /** The name of the event. */ - name: string; - /** The attributes of the event. */ - attributes?: SpanAttributes; -}