From 712493efa6e7d22fc96cbaaf7db6cfae91e808a2 Mon Sep 17 00:00:00 2001 From: Martin Kuba Date: Fri, 29 Mar 2024 16:55:08 -0700 Subject: [PATCH] moved AnyValue to Log API, updated changelog --- api/CHANGELOG.md | 2 -- api/src/common/Attributes.ts | 12 -------- api/src/index.ts | 7 +---- experimental/CHANGELOG.md | 4 ++- .../packages/api-events/src/types/Event.ts | 3 +- experimental/packages/api-logs/src/index.ts | 1 + .../packages/api-logs/src/types/AnyValue.ts | 29 +++++++++++++++++++ .../packages/api-logs/src/types/LogRecord.ts | 3 +- .../packages/sdk-logs/src/LogRecord.ts | 2 +- 9 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 experimental/packages/api-logs/src/types/AnyValue.ts diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index 2d413fb75e..f33bcbaddf 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -8,8 +8,6 @@ All notable changes to this project will be documented in this file. ### :rocket: (Enhancement) -* feat(api): add AnyValue and AnyValueMap types [#4575](https://github.com/open-telemetry/opentelemetry-js/pull/4575) - ### :bug: (Bug Fix) ### :books: (Refine Doc) diff --git a/api/src/common/Attributes.ts b/api/src/common/Attributes.ts index d02187302b..53a8166d84 100644 --- a/api/src/common/Attributes.ts +++ b/api/src/common/Attributes.ts @@ -35,15 +35,3 @@ export type AttributeValue = | Array | Array | Array; - -/** - * 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/api/src/index.ts b/api/src/index.ts index 108e56c6ee..c5dbe1685b 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -18,12 +18,7 @@ export { BaggageEntry, BaggageEntryMetadata, Baggage } from './baggage/types'; export { baggageEntryMetadataFromString } from './baggage/utils'; export { Exception } from './common/Exception'; export { HrTime, TimeInput } from './common/Time'; -export { - Attributes, - AttributeValue, - AnyValue, - AnyValueMap, -} from './common/Attributes'; +export { Attributes, AttributeValue } from './common/Attributes'; // Context APIs export { createContextKey, ROOT_CONTEXT } from './context/context'; diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index b8153427b9..eb535147df 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -21,12 +21,14 @@ 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-events)!: added data field to the Event interface [4575](https://github.com/open-telemetry/opentelemetry-js/pull/4575) +* 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) * refactor(instr-http): use exported strings for semconv. [#4573](https://github.com/open-telemetry/opentelemetry-js/pull/4573/) @JamieDanielson * 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/src/types/Event.ts b/experimental/packages/api-events/src/types/Event.ts index 00f68aea14..58456311cb 100644 --- a/experimental/packages/api-events/src/types/Event.ts +++ b/experimental/packages/api-events/src/types/Event.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { AnyValue, Attributes } from '@opentelemetry/api'; +import { Attributes } from '@opentelemetry/api'; +import { AnyValue } from '@opentelemetry/api-logs'; export interface Event { /** diff --git a/experimental/packages/api-logs/src/index.ts b/experimental/packages/api-logs/src/index.ts index 34b4d8e20e..3ea2ae39c8 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 0000000000..7a97de7ed6 --- /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 f4e8b20038..85d5e4ff4d 100644 --- a/experimental/packages/api-logs/src/types/LogRecord.ts +++ b/experimental/packages/api-logs/src/types/LogRecord.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { AnyValue, AnyValueMap, Context, TimeInput } from '@opentelemetry/api'; +import { Context, TimeInput } from '@opentelemetry/api'; +import { AnyValue, AnyValueMap } from './AnyValue'; export type LogBody = AnyValue; export type LogAttributes = AnyValueMap; diff --git a/experimental/packages/sdk-logs/src/LogRecord.ts b/experimental/packages/sdk-logs/src/LogRecord.ts index 39162597d1..abc4f45285 100644 --- a/experimental/packages/sdk-logs/src/LogRecord.ts +++ b/experimental/packages/sdk-logs/src/LogRecord.ts @@ -157,7 +157,7 @@ export class LogRecord implements ReadableLogRecord { return this; } - public setBody(body: string) { + public setBody(body: LogBody) { this.body = body; return this; }