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(contrib-test-utils): copy soon-to-be-removed types from @opentelemetry/otlp-transformer #2573

42 changes: 38 additions & 4 deletions packages/opentelemetry-test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,41 @@
* limitations under the License.
*/

export * from './resource-assertions';
export * from './test-fixtures';
export * from './test-utils';
export * from './instrumentations';
export {
assertCloudResource,
assertContainerResource,
assertEmptyResource,
assertHostResource,
assertK8sResource,
assertProcessResource,
assertServiceResource,
assertTelemetrySDKResource,
} from './resource-assertions';
export { OtlpSpanKind } from './otlp-types';
export {
createTestNodeSdk,
runTestFixture,
TestSpan,
RunTestFixtureOptions,
TestCollector,
} from './test-fixtures';
export {
assertPropagation,
assertSpan,
cleanUpDocker,
getPackageVersion,
initMeterProvider,
TimedEvent,
startDocker,
TestMetricReader,
} from './test-utils';
export {
getInstrumentation,
getTestMemoryExporter,
getTestSpans,
mochaHooks,
registerInstrumentationTesting,
registerInstrumentationTestingProvider,
resetMemoryExporter,
setTestMemoryExporter,
} from './instrumentations';
167 changes: 167 additions & 0 deletions packages/opentelemetry-test-utils/src/otlp-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* 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.
*/

export enum OtlpSpanKind {
UNSPECIFIED = 0,
INTERNAL = 1,
SERVER = 2,
CLIENT = 3,
PRODUCER = 4,
CONSUMER = 5,
}

/** Properties of a KeyValueList. */
interface IKeyValueList {
/** KeyValueList values */
values: IKeyValue[];
}

/** Properties of an ArrayValue. */
interface IArrayValue {
/** ArrayValue values */
values: IAnyValue[];
}

/** Properties of an AnyValue. */
interface IAnyValue {
/** AnyValue stringValue */
stringValue?: string | null;
/** AnyValue boolValue */
boolValue?: boolean | null;
/** AnyValue intValue */
intValue?: number | null;
/** AnyValue doubleValue */
doubleValue?: number | null;
/** AnyValue arrayValue */
arrayValue?: IArrayValue;
/** AnyValue kvlistValue */
kvlistValue?: IKeyValueList;
/** AnyValue bytesValue */
bytesValue?: Uint8Array;
}

/** Properties of a KeyValue. */
interface IKeyValue {
/** KeyValue key */
key: string;
/** KeyValue value */
value: IAnyValue;
}

/** Properties of an InstrumentationScope. */
export interface IInstrumentationScope {
/** InstrumentationScope name */
name: string;
/** InstrumentationScope version */
version?: string;
/** InstrumentationScope attributes */
attributes?: IKeyValue[];
/** InstrumentationScope droppedAttributesCount */
droppedAttributesCount?: number;
}

/** Properties of a Resource. */
export interface IResource {
/** Resource attributes */
attributes: IKeyValue[];
/** Resource droppedAttributesCount */
droppedAttributesCount: number;
}

interface LongBits {
low: number;
high: number;
}

type Fixed64 = LongBits | string | number;

/** Properties of an Event. */
interface IEvent {
/** Event timeUnixNano */
timeUnixNano: Fixed64;
/** Event name */
name: string;
/** Event attributes */
attributes: IKeyValue[];
/** Event droppedAttributesCount */
droppedAttributesCount: number;
}

/** Properties of a Link. */
interface ILink {
/** Link traceId */
traceId: string | Uint8Array;
/** Link spanId */
spanId: string | Uint8Array;
/** Link traceState */
traceState?: string;
/** Link attributes */
attributes: IKeyValue[];
/** Link droppedAttributesCount */
droppedAttributesCount: number;
}

/** Properties of a Status. */
interface IStatus {
/** Status message */
message?: string;
/** Status code */
code: EStatusCode;
}

/** StatusCode enum. */
const enum EStatusCode {
/** The default status. */
STATUS_CODE_UNSET = 0,
/** The Span has been evaluated by an Application developer or Operator to have completed successfully. */
STATUS_CODE_OK = 1,
/** The Span contains an error. */
STATUS_CODE_ERROR = 2,
}

/** Properties of a Span. */
export interface ISpan {
/** Span traceId */
traceId: string | Uint8Array;
/** Span spanId */
spanId: string | Uint8Array;
/** Span traceState */
traceState?: string | null;
/** Span parentSpanId */
parentSpanId?: string | Uint8Array;
/** Span name */
name: string;
/** Span kind */
kind: OtlpSpanKind;
/** Span startTimeUnixNano */
startTimeUnixNano: Fixed64;
/** Span endTimeUnixNano */
endTimeUnixNano: Fixed64;
/** Span attributes */
attributes: IKeyValue[];
/** Span droppedAttributesCount */
droppedAttributesCount: number;
/** Span events */
events: IEvent[];
/** Span droppedEventsCount */
droppedEventsCount: number;
/** Span links */
links: ILink[];
/** Span droppedLinksCount */
droppedLinksCount: number;
/** Span status */
status: IStatus;
}
15 changes: 1 addition & 14 deletions packages/opentelemetry-test-utils/src/test-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ import type { AddressInfo } from 'net';
import { URL } from 'url';
import { createGunzip } from 'zlib';

import {
IInstrumentationScope,
IResource,
ISpan,
} from '@opentelemetry/otlp-transformer';
import { NodeSDK, tracing } from '@opentelemetry/sdk-node';
import type { Instrumentation } from '@opentelemetry/instrumentation';
import { IInstrumentationScope, IResource, ISpan } from './otlp-types';

/**
* A utility for scripts that will be run with `runTestFixture()` to create an
Expand All @@ -55,15 +51,6 @@ export function createTestNodeSdk(opts: {
return sdk;
}

export enum OtlpSpanKind {
UNSPECIFIED = 0,
INTERNAL = 1,
SERVER = 2,
CLIENT = 3,
PRODUCER = 4,
CONSUMER = 5,
}

// TestSpan is an OTLP span plus references to `resource` and
// `instrumentationScope` that are shared between multiple spans in the
// protocol.
Expand Down
Loading