diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 992c239473f..0b286f0bc97 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -21,6 +21,8 @@ All notable changes to experimental packages in this project will be documented * 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. * feat(api-events)!: removed domain from the Events API [#4569](/~https://github.com/open-telemetry/opentelemetry-js/pull/4569) * fix(events-api)!: renamed EventEmitter to EventLogger in the Events API [#4569](/~https://github.com/open-telemetry/opentelemetry-js/pull/4568) +* feat(api-logs)!: changed LogRecord body data type to AnyValue [#4575](/~https://github.com/open-telemetry/opentelemetry-js/pull/4575) +and AnyValueMap types [#4575](/~https://github.com/open-telemetry/opentelemetry-js/pull/4575) ### :rocket: (Enhancement) @@ -28,6 +30,7 @@ All notable changes to experimental packages in this project will be documented * refactor(instr-http): use exported strings for semconv. [#4573](/~https://github.com/open-telemetry/opentelemetry-js/pull/4573/) @JamieDanielson * perf(instrumentation-http): remove obvious temp allocations [#4576](/~https://github.com/open-telemetry/opentelemetry-js/pull/4576) @Samuron * feat(sdk-node): add `HostDetector` as default resource detector +* feat(api-events): added data field to the Event interface [4575](/~https://github.com/open-telemetry/opentelemetry-js/pull/4575) ### :bug: (Bug Fix) diff --git a/experimental/packages/api-events/package.json b/experimental/packages/api-events/package.json index f1b40f080e3..2c40d47717e 100644 --- a/experimental/packages/api-events/package.json +++ b/experimental/packages/api-events/package.json @@ -61,7 +61,8 @@ "access": "public" }, "dependencies": { - "@opentelemetry/api": "^1.0.0" + "@opentelemetry/api": "^1.0.0", + "@opentelemetry/api-logs": "0.49.1" }, "devDependencies": { "@types/mocha": "10.0.6", diff --git a/experimental/packages/api-events/src/types/Event.ts b/experimental/packages/api-events/src/types/Event.ts index 03e4ef89dbd..58456311cbf 100644 --- a/experimental/packages/api-events/src/types/Event.ts +++ b/experimental/packages/api-events/src/types/Event.ts @@ -15,6 +15,7 @@ */ import { Attributes } from '@opentelemetry/api'; +import { AnyValue } from '@opentelemetry/api-logs'; export interface Event { /** @@ -27,6 +28,12 @@ export interface Event { */ name: string; + /** + * Data that describes the event. + * Intended to be used by instrumentation libraries. + */ + data?: AnyValue; + /** * Additional attributes that describe the event. */ diff --git a/experimental/packages/api-events/tsconfig.esm.json b/experimental/packages/api-events/tsconfig.esm.json index f0383c00422..91cc36db7ae 100644 --- a/experimental/packages/api-events/tsconfig.esm.json +++ b/experimental/packages/api-events/tsconfig.esm.json @@ -11,6 +11,9 @@ "references": [ { "path": "../../../api" + }, + { + "path": "../api-logs" } ] } diff --git a/experimental/packages/api-events/tsconfig.esnext.json b/experimental/packages/api-events/tsconfig.esnext.json index 218899ff2da..80e34599a90 100644 --- a/experimental/packages/api-events/tsconfig.esnext.json +++ b/experimental/packages/api-events/tsconfig.esnext.json @@ -11,6 +11,9 @@ "references": [ { "path": "../../../api" + }, + { + "path": "../api-logs" } ] } diff --git a/experimental/packages/api-events/tsconfig.json b/experimental/packages/api-events/tsconfig.json index 5849e79c034..40ca71c181e 100644 --- a/experimental/packages/api-events/tsconfig.json +++ b/experimental/packages/api-events/tsconfig.json @@ -12,6 +12,9 @@ "references": [ { "path": "../../../api" + }, + { + "path": "../api-logs" } ] } diff --git a/experimental/packages/api-logs/src/index.ts b/experimental/packages/api-logs/src/index.ts index 34b4d8e20ee..3ea2ae39c8b 100644 --- a/experimental/packages/api-logs/src/index.ts +++ b/experimental/packages/api-logs/src/index.ts @@ -18,6 +18,7 @@ export * from './types/Logger'; export * from './types/LoggerProvider'; export * from './types/LogRecord'; export * from './types/LoggerOptions'; +export * from './types/AnyValue'; export * from './NoopLogger'; export * from './NoopLoggerProvider'; diff --git a/experimental/packages/api-logs/src/types/AnyValue.ts b/experimental/packages/api-logs/src/types/AnyValue.ts new file mode 100644 index 00000000000..7a97de7ed60 --- /dev/null +++ b/experimental/packages/api-logs/src/types/AnyValue.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 { AttributeValue } from '@opentelemetry/api'; + +/** + * AnyValueMap is a map from string to AnyValue (attribute value or a nested map) + */ +export interface AnyValueMap { + [attributeKey: string]: AnyValue | undefined; +} + +/** + * AnyValue is a either an attribute value or a map of AnyValue(s) + */ +export type AnyValue = AttributeValue | AnyValueMap; diff --git a/experimental/packages/api-logs/src/types/LogRecord.ts b/experimental/packages/api-logs/src/types/LogRecord.ts index 69dd14f7cba..85d5e4ff4dd 100644 --- a/experimental/packages/api-logs/src/types/LogRecord.ts +++ b/experimental/packages/api-logs/src/types/LogRecord.ts @@ -14,12 +14,11 @@ * limitations under the License. */ -import { AttributeValue, Context, TimeInput } from '@opentelemetry/api'; +import { Context, TimeInput } from '@opentelemetry/api'; +import { AnyValue, AnyValueMap } from './AnyValue'; -export type LogAttributeValue = AttributeValue | LogAttributes; -export interface LogAttributes { - [attributeKey: string]: LogAttributeValue | undefined; -} +export type LogBody = AnyValue; +export type LogAttributes = AnyValueMap; export enum SeverityNumber { UNSPECIFIED = 0, @@ -73,7 +72,7 @@ export interface LogRecord { /** * A value containing the body of the log record. */ - body?: string; + body?: LogBody; /** * Attributes that define the log record. diff --git a/experimental/packages/sdk-logs/src/LogRecord.ts b/experimental/packages/sdk-logs/src/LogRecord.ts index d827c7fa1dd..abc4f452855 100644 --- a/experimental/packages/sdk-logs/src/LogRecord.ts +++ b/experimental/packages/sdk-logs/src/LogRecord.ts @@ -26,7 +26,7 @@ import type { IResource } from '@opentelemetry/resources'; import type { ReadableLogRecord } from './export/ReadableLogRecord'; import type { LogRecordLimits } from './types'; -import { LogAttributes } from '@opentelemetry/api-logs'; +import { LogAttributes, LogBody } from '@opentelemetry/api-logs'; import { LoggerProviderSharedState } from './internal/LoggerProviderSharedState'; export class LogRecord implements ReadableLogRecord { @@ -38,7 +38,7 @@ export class LogRecord implements ReadableLogRecord { readonly attributes: logsAPI.LogAttributes = {}; private _severityText?: string; private _severityNumber?: logsAPI.SeverityNumber; - private _body?: string; + private _body?: LogBody; private totalAttributesCount: number = 0; private _isReadonly: boolean = false; @@ -64,13 +64,13 @@ export class LogRecord implements ReadableLogRecord { return this._severityNumber; } - set body(body: string | undefined) { + set body(body: LogBody | undefined) { if (this._isLogRecordReadonly()) { return; } this._body = body; } - get body(): string | undefined { + get body(): LogBody | undefined { return this._body; } @@ -157,7 +157,7 @@ export class LogRecord implements ReadableLogRecord { return this; } - public setBody(body: string) { + public setBody(body: LogBody) { this.body = body; return this; } diff --git a/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts b/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts index 2dc3ece8658..2af71de76be 100644 --- a/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts +++ b/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts @@ -17,7 +17,11 @@ import type { IResource } from '@opentelemetry/resources'; import type { HrTime, SpanContext } from '@opentelemetry/api'; import type { InstrumentationScope } from '@opentelemetry/core'; -import type { LogAttributes, SeverityNumber } from '@opentelemetry/api-logs'; +import type { + LogBody, + LogAttributes, + SeverityNumber, +} from '@opentelemetry/api-logs'; export interface ReadableLogRecord { readonly hrTime: HrTime; @@ -25,7 +29,7 @@ export interface ReadableLogRecord { readonly spanContext?: SpanContext; readonly severityText?: string; readonly severityNumber?: SeverityNumber; - readonly body?: string; + readonly body?: LogBody; readonly resource: IResource; readonly instrumentationScope: InstrumentationScope; readonly attributes: LogAttributes;