Skip to content

Commit 23a345d

Browse files
feat(contrib-test-utils): copy soon-to-be-removed types from @opentelemetry/otlp-transformer (#2573)
Co-authored-by: Jackson Weber <[email protected]>
1 parent e3c9150 commit 23a345d

File tree

3 files changed

+206
-18
lines changed

3 files changed

+206
-18
lines changed

packages/opentelemetry-test-utils/src/index.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,41 @@
1414
* limitations under the License.
1515
*/
1616

17-
export * from './resource-assertions';
18-
export * from './test-fixtures';
19-
export * from './test-utils';
20-
export * from './instrumentations';
17+
export {
18+
assertCloudResource,
19+
assertContainerResource,
20+
assertEmptyResource,
21+
assertHostResource,
22+
assertK8sResource,
23+
assertProcessResource,
24+
assertServiceResource,
25+
assertTelemetrySDKResource,
26+
} from './resource-assertions';
27+
export { OtlpSpanKind } from './otlp-types';
28+
export {
29+
createTestNodeSdk,
30+
runTestFixture,
31+
TestSpan,
32+
RunTestFixtureOptions,
33+
TestCollector,
34+
} from './test-fixtures';
35+
export {
36+
assertPropagation,
37+
assertSpan,
38+
cleanUpDocker,
39+
getPackageVersion,
40+
initMeterProvider,
41+
TimedEvent,
42+
startDocker,
43+
TestMetricReader,
44+
} from './test-utils';
45+
export {
46+
getInstrumentation,
47+
getTestMemoryExporter,
48+
getTestSpans,
49+
mochaHooks,
50+
registerInstrumentationTesting,
51+
registerInstrumentationTestingProvider,
52+
resetMemoryExporter,
53+
setTestMemoryExporter,
54+
} from './instrumentations';
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export enum OtlpSpanKind {
18+
UNSPECIFIED = 0,
19+
INTERNAL = 1,
20+
SERVER = 2,
21+
CLIENT = 3,
22+
PRODUCER = 4,
23+
CONSUMER = 5,
24+
}
25+
26+
/** Properties of a KeyValueList. */
27+
interface IKeyValueList {
28+
/** KeyValueList values */
29+
values: IKeyValue[];
30+
}
31+
32+
/** Properties of an ArrayValue. */
33+
interface IArrayValue {
34+
/** ArrayValue values */
35+
values: IAnyValue[];
36+
}
37+
38+
/** Properties of an AnyValue. */
39+
interface IAnyValue {
40+
/** AnyValue stringValue */
41+
stringValue?: string | null;
42+
/** AnyValue boolValue */
43+
boolValue?: boolean | null;
44+
/** AnyValue intValue */
45+
intValue?: number | null;
46+
/** AnyValue doubleValue */
47+
doubleValue?: number | null;
48+
/** AnyValue arrayValue */
49+
arrayValue?: IArrayValue;
50+
/** AnyValue kvlistValue */
51+
kvlistValue?: IKeyValueList;
52+
/** AnyValue bytesValue */
53+
bytesValue?: Uint8Array;
54+
}
55+
56+
/** Properties of a KeyValue. */
57+
interface IKeyValue {
58+
/** KeyValue key */
59+
key: string;
60+
/** KeyValue value */
61+
value: IAnyValue;
62+
}
63+
64+
/** Properties of an InstrumentationScope. */
65+
export interface IInstrumentationScope {
66+
/** InstrumentationScope name */
67+
name: string;
68+
/** InstrumentationScope version */
69+
version?: string;
70+
/** InstrumentationScope attributes */
71+
attributes?: IKeyValue[];
72+
/** InstrumentationScope droppedAttributesCount */
73+
droppedAttributesCount?: number;
74+
}
75+
76+
/** Properties of a Resource. */
77+
export interface IResource {
78+
/** Resource attributes */
79+
attributes: IKeyValue[];
80+
/** Resource droppedAttributesCount */
81+
droppedAttributesCount: number;
82+
}
83+
84+
interface LongBits {
85+
low: number;
86+
high: number;
87+
}
88+
89+
type Fixed64 = LongBits | string | number;
90+
91+
/** Properties of an Event. */
92+
interface IEvent {
93+
/** Event timeUnixNano */
94+
timeUnixNano: Fixed64;
95+
/** Event name */
96+
name: string;
97+
/** Event attributes */
98+
attributes: IKeyValue[];
99+
/** Event droppedAttributesCount */
100+
droppedAttributesCount: number;
101+
}
102+
103+
/** Properties of a Link. */
104+
interface ILink {
105+
/** Link traceId */
106+
traceId: string | Uint8Array;
107+
/** Link spanId */
108+
spanId: string | Uint8Array;
109+
/** Link traceState */
110+
traceState?: string;
111+
/** Link attributes */
112+
attributes: IKeyValue[];
113+
/** Link droppedAttributesCount */
114+
droppedAttributesCount: number;
115+
}
116+
117+
/** Properties of a Status. */
118+
interface IStatus {
119+
/** Status message */
120+
message?: string;
121+
/** Status code */
122+
code: EStatusCode;
123+
}
124+
125+
/** StatusCode enum. */
126+
const enum EStatusCode {
127+
/** The default status. */
128+
STATUS_CODE_UNSET = 0,
129+
/** The Span has been evaluated by an Application developer or Operator to have completed successfully. */
130+
STATUS_CODE_OK = 1,
131+
/** The Span contains an error. */
132+
STATUS_CODE_ERROR = 2,
133+
}
134+
135+
/** Properties of a Span. */
136+
export interface ISpan {
137+
/** Span traceId */
138+
traceId: string | Uint8Array;
139+
/** Span spanId */
140+
spanId: string | Uint8Array;
141+
/** Span traceState */
142+
traceState?: string | null;
143+
/** Span parentSpanId */
144+
parentSpanId?: string | Uint8Array;
145+
/** Span name */
146+
name: string;
147+
/** Span kind */
148+
kind: OtlpSpanKind;
149+
/** Span startTimeUnixNano */
150+
startTimeUnixNano: Fixed64;
151+
/** Span endTimeUnixNano */
152+
endTimeUnixNano: Fixed64;
153+
/** Span attributes */
154+
attributes: IKeyValue[];
155+
/** Span droppedAttributesCount */
156+
droppedAttributesCount: number;
157+
/** Span events */
158+
events: IEvent[];
159+
/** Span droppedEventsCount */
160+
droppedEventsCount: number;
161+
/** Span links */
162+
links: ILink[];
163+
/** Span droppedLinksCount */
164+
droppedLinksCount: number;
165+
/** Span status */
166+
status: IStatus;
167+
}

packages/opentelemetry-test-utils/src/test-fixtures.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ import type { AddressInfo } from 'net';
2424
import { URL } from 'url';
2525
import { createGunzip } from 'zlib';
2626

27-
import {
28-
IInstrumentationScope,
29-
IResource,
30-
ISpan,
31-
} from '@opentelemetry/otlp-transformer';
3227
import { NodeSDK, tracing } from '@opentelemetry/sdk-node';
3328
import type { Instrumentation } from '@opentelemetry/instrumentation';
29+
import { IInstrumentationScope, IResource, ISpan } from './otlp-types';
3430

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

58-
export enum OtlpSpanKind {
59-
UNSPECIFIED = 0,
60-
INTERNAL = 1,
61-
SERVER = 2,
62-
CLIENT = 3,
63-
PRODUCER = 4,
64-
CONSUMER = 5,
65-
}
66-
6754
// TestSpan is an OTLP span plus references to `resource` and
6855
// `instrumentationScope` that are shared between multiple spans in the
6956
// protocol.

0 commit comments

Comments
 (0)