Skip to content

Commit d66e1d7

Browse files
authored
Add data field to the Event interface (#4575)
* add `data` field to the Event interface * updated body field in the Logs SDK * updated changelog to breaking change * lint * added dedicated type for event data field * added AnyValue and AnyValueMap types for Event data * changed body type to LogBody * markdown lint * updated Logs SDK * changed to non-breaking change in the core API * moved AnyValue to Log API, updated changelog
1 parent f3aedb7 commit d66e1d7

File tree

11 files changed

+67
-14
lines changed

11 files changed

+67
-14
lines changed

experimental/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ All notable changes to experimental packages in this project will be documented
2121
* was used internally to keep track of the compression to use but was unintentionally exposed to the users. It allowed to read and write the value, writing, however, would have no effect.
2222
* feat(api-events)!: removed domain from the Events API [#4569](https://github.com/open-telemetry/opentelemetry-js/pull/4569)
2323
* fix(events-api)!: renamed EventEmitter to EventLogger in the Events API [#4569](https://github.com/open-telemetry/opentelemetry-js/pull/4568)
24+
* feat(api-logs)!: changed LogRecord body data type to AnyValue [#4575](https://github.com/open-telemetry/opentelemetry-js/pull/4575)
25+
and AnyValueMap types [#4575](https://github.com/open-telemetry/opentelemetry-js/pull/4575)
2426

2527
### :rocket: (Enhancement)
2628

2729
* feat(opentelemetry-instrumentation-xhr): optionally ignore network events [#4571](https://github.com/open-telemetry/opentelemetry-js/pull/4571/) @mustafahaddara
2830
* refactor(instr-http): use exported strings for semconv. [#4573](https://github.com/open-telemetry/opentelemetry-js/pull/4573/) @JamieDanielson
2931
* perf(instrumentation-http): remove obvious temp allocations [#4576](https://github.com/open-telemetry/opentelemetry-js/pull/4576) @Samuron
3032
* feat(sdk-node): add `HostDetector` as default resource detector
33+
* feat(api-events): added data field to the Event interface [4575](https://github.com/open-telemetry/opentelemetry-js/pull/4575)
3134

3235
### :bug: (Bug Fix)
3336

experimental/packages/api-events/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"access": "public"
6262
},
6363
"dependencies": {
64-
"@opentelemetry/api": "^1.0.0"
64+
"@opentelemetry/api": "^1.0.0",
65+
"@opentelemetry/api-logs": "0.49.1"
6566
},
6667
"devDependencies": {
6768
"@types/mocha": "10.0.6",

experimental/packages/api-events/src/types/Event.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { Attributes } from '@opentelemetry/api';
18+
import { AnyValue } from '@opentelemetry/api-logs';
1819

1920
export interface Event {
2021
/**
@@ -27,6 +28,12 @@ export interface Event {
2728
*/
2829
name: string;
2930

31+
/**
32+
* Data that describes the event.
33+
* Intended to be used by instrumentation libraries.
34+
*/
35+
data?: AnyValue;
36+
3037
/**
3138
* Additional attributes that describe the event.
3239
*/

experimental/packages/api-events/tsconfig.esm.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"references": [
1212
{
1313
"path": "../../../api"
14+
},
15+
{
16+
"path": "../api-logs"
1417
}
1518
]
1619
}

experimental/packages/api-events/tsconfig.esnext.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"references": [
1212
{
1313
"path": "../../../api"
14+
},
15+
{
16+
"path": "../api-logs"
1417
}
1518
]
1619
}

experimental/packages/api-events/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"references": [
1313
{
1414
"path": "../../../api"
15+
},
16+
{
17+
"path": "../api-logs"
1518
}
1619
]
1720
}

experimental/packages/api-logs/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './types/Logger';
1818
export * from './types/LoggerProvider';
1919
export * from './types/LogRecord';
2020
export * from './types/LoggerOptions';
21+
export * from './types/AnyValue';
2122
export * from './NoopLogger';
2223
export * from './NoopLoggerProvider';
2324

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
import { AttributeValue } from '@opentelemetry/api';
18+
19+
/**
20+
* AnyValueMap is a map from string to AnyValue (attribute value or a nested map)
21+
*/
22+
export interface AnyValueMap {
23+
[attributeKey: string]: AnyValue | undefined;
24+
}
25+
26+
/**
27+
* AnyValue is a either an attribute value or a map of AnyValue(s)
28+
*/
29+
export type AnyValue = AttributeValue | AnyValueMap;

experimental/packages/api-logs/src/types/LogRecord.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { AttributeValue, Context, TimeInput } from '@opentelemetry/api';
17+
import { Context, TimeInput } from '@opentelemetry/api';
18+
import { AnyValue, AnyValueMap } from './AnyValue';
1819

19-
export type LogAttributeValue = AttributeValue | LogAttributes;
20-
export interface LogAttributes {
21-
[attributeKey: string]: LogAttributeValue | undefined;
22-
}
20+
export type LogBody = AnyValue;
21+
export type LogAttributes = AnyValueMap;
2322

2423
export enum SeverityNumber {
2524
UNSPECIFIED = 0,
@@ -73,7 +72,7 @@ export interface LogRecord {
7372
/**
7473
* A value containing the body of the log record.
7574
*/
76-
body?: string;
75+
body?: LogBody;
7776

7877
/**
7978
* Attributes that define the log record.

experimental/packages/sdk-logs/src/LogRecord.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { IResource } from '@opentelemetry/resources';
2626

2727
import type { ReadableLogRecord } from './export/ReadableLogRecord';
2828
import type { LogRecordLimits } from './types';
29-
import { LogAttributes } from '@opentelemetry/api-logs';
29+
import { LogAttributes, LogBody } from '@opentelemetry/api-logs';
3030
import { LoggerProviderSharedState } from './internal/LoggerProviderSharedState';
3131

3232
export class LogRecord implements ReadableLogRecord {
@@ -38,7 +38,7 @@ export class LogRecord implements ReadableLogRecord {
3838
readonly attributes: logsAPI.LogAttributes = {};
3939
private _severityText?: string;
4040
private _severityNumber?: logsAPI.SeverityNumber;
41-
private _body?: string;
41+
private _body?: LogBody;
4242
private totalAttributesCount: number = 0;
4343

4444
private _isReadonly: boolean = false;
@@ -64,13 +64,13 @@ export class LogRecord implements ReadableLogRecord {
6464
return this._severityNumber;
6565
}
6666

67-
set body(body: string | undefined) {
67+
set body(body: LogBody | undefined) {
6868
if (this._isLogRecordReadonly()) {
6969
return;
7070
}
7171
this._body = body;
7272
}
73-
get body(): string | undefined {
73+
get body(): LogBody | undefined {
7474
return this._body;
7575
}
7676

@@ -157,7 +157,7 @@ export class LogRecord implements ReadableLogRecord {
157157
return this;
158158
}
159159

160-
public setBody(body: string) {
160+
public setBody(body: LogBody) {
161161
this.body = body;
162162
return this;
163163
}

experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717
import type { IResource } from '@opentelemetry/resources';
1818
import type { HrTime, SpanContext } from '@opentelemetry/api';
1919
import type { InstrumentationScope } from '@opentelemetry/core';
20-
import type { LogAttributes, SeverityNumber } from '@opentelemetry/api-logs';
20+
import type {
21+
LogBody,
22+
LogAttributes,
23+
SeverityNumber,
24+
} from '@opentelemetry/api-logs';
2125

2226
export interface ReadableLogRecord {
2327
readonly hrTime: HrTime;
2428
readonly hrTimeObserved: HrTime;
2529
readonly spanContext?: SpanContext;
2630
readonly severityText?: string;
2731
readonly severityNumber?: SeverityNumber;
28-
readonly body?: string;
32+
readonly body?: LogBody;
2933
readonly resource: IResource;
3034
readonly instrumentationScope: InstrumentationScope;
3135
readonly attributes: LogAttributes;

0 commit comments

Comments
 (0)