Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit ae9bead

Browse files
dyladanvmarchaud
andauthored
feat: define common attributes type (#142)
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
1 parent 474f853 commit ae9bead

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

src/common/Attributes.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
/**
18+
* Attributes is a map from string to attribute values.
19+
*/
20+
export interface Attributes {
21+
[attributeKey: string]: AttributeValue | undefined;
22+
}
23+
24+
/**
25+
* Attribute values may be any non-nullish primitive value except an object.
26+
*
27+
* null or undefined attribute values are invalid and will result in undefined behavior.
28+
*/
29+
export type AttributeValue =
30+
| string
31+
| number
32+
| boolean
33+
| Array<null | undefined | string>
34+
| Array<null | undefined | number>
35+
| Array<null | undefined | boolean>;

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './baggage/types';
1818
export { baggageEntryMetadataFromString } from './baggage/utils';
1919
export * from './common/Exception';
2020
export * from './common/Time';
21+
export * from './common/Attributes';
2122
export * from './diag';
2223
export * from './propagation/TextMapPropagator';
2324
export * from './trace/attributes';

src/trace/attributes.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
export interface SpanAttributes {
18-
[attributeKey: string]: SpanAttributeValue | undefined;
19-
}
17+
import { Attributes, AttributeValue } from '../common/Attributes';
2018

2119
/**
22-
* Attribute values may be any non-nullish primitive value except an object.
23-
*
24-
* null or undefined attribute values are invalid and will result in undefined behavior.
20+
* @deprecated please use Attributes
21+
*/
22+
export type SpanAttributes = Attributes;
23+
24+
/**
25+
* @deprecated please use AttributeValue
2526
*/
26-
export type SpanAttributeValue =
27-
| string
28-
| number
29-
| boolean
30-
| Array<null | undefined | string>
31-
| Array<null | undefined | number>
32-
| Array<null | undefined | boolean>;
27+
export type SpanAttributeValue = AttributeValue;

0 commit comments

Comments
 (0)