Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: open-telemetry/opentelemetry-js-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.4
Choose a base ref
...
head repository: open-telemetry/opentelemetry-js-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.1.0
Choose a head ref
  • 8 commits
  • 19 files changed
  • 4 contributors

Commits on Dec 22, 2021

  1. Copy the full SHA
    80d617b View commit details

Commits on Dec 28, 2021

  1. Copy the full SHA
    474f853 View commit details

Commits on Jan 8, 2022

  1. feat: define common attributes type (#142)

    Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
    dyladan and vmarchaud authored Jan 8, 2022
    Copy the full SHA
    ae9bead View commit details

Commits on Jan 13, 2022

  1. feat(trace): add optional schema url to TracerProvider.getTracer (#129)

    Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
    legendecas and vmarchaud authored Jan 13, 2022
    Copy the full SHA
    aa65fc6 View commit details

Commits on Jan 19, 2022

  1. feat: add tracestate implementation to api (#147)

    Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
    srikanthccv and vmarchaud authored Jan 19, 2022
    Copy the full SHA
    82842c7 View commit details

Commits on Jan 25, 2022

  1. Copy the full SHA
    b125324 View commit details
  2. docs: add notes on attribute key descriptor (#155)

    Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
    legendecas and vmarchaud authored Jan 25, 2022
    Copy the full SHA
    1ed52fd View commit details

Commits on Jan 27, 2022

  1. chore: release 1.1.0 (#151)

    dyladan authored Jan 27, 2022
    Copy the full SHA
    24f1cb8 View commit details
18 changes: 11 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -10,13 +10,16 @@ jobs:
strategy:
fail-fast: false
matrix:
container: ["node:8", "node:10", "node:12", "node:14", "node:16"]
node: ["8", "10", "12", "14", "16"]
runs-on: ubuntu-latest
container:
image: ${{ matrix.container }}
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- name: Install Dependencies
run: npm install
@@ -29,18 +32,19 @@ jobs:

- name: Report Coverage
run: npm run codecov
if: ${{ matrix.container == 'node:14' }}
if: ${{ matrix.node == '14' }}

browser-tests:
runs-on: ubuntu-latest
container:
image: circleci/node:12-browsers
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Permission Setup
run: sudo chmod -R 777 /github /__w

- name: Checkout
uses: actions/checkout@v2

- name: Install Dependencies
run: npm install

14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,20 @@

All notable changes to this project will be documented in this file.

## [1.1.0](https://www.github.com/open-telemetry/opentelemetry-js-api/compare/v1.0.4...v1.1.0) (2022-01-25)


### Features

* add tracestate implementation to api ([#147](https://www.github.com/open-telemetry/opentelemetry-js-api/issues/147)) ([82842c7](https://www.github.com/open-telemetry/opentelemetry-js-api/commit/82842c7097614e6ece99e73838ac5e94ff5460b7))
* define common attributes type ([#142](https://www.github.com/open-telemetry/opentelemetry-js-api/issues/142)) ([ae9bead](https://www.github.com/open-telemetry/opentelemetry-js-api/commit/ae9bead17750d35dec4b63cfae098087666abc85))
* **trace:** add optional schema url to TracerProvider.getTracer ([#129](https://www.github.com/open-telemetry/opentelemetry-js-api/issues/129)) ([aa65fc6](https://www.github.com/open-telemetry/opentelemetry-js-api/commit/aa65fc66809d45090d6e4951c265386d17ccc6f6))


### Bug Fixes

* export tracer options ([#154](https://www.github.com/open-telemetry/opentelemetry-js-api/issues/154)) ([b125324](https://www.github.com/open-telemetry/opentelemetry-js-api/commit/b125324438fb2f24eb80c7c6673afc8cfc99575e))

### [1.0.4](https://www.github.com/open-telemetry/opentelemetry-js-api/compare/v1.0.3...v1.0.4) (2021-12-18)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentelemetry/api",
"version": "1.0.4",
"version": "1.1.0",
"description": "Public API for OpenTelemetry",
"main": "build/src/index.js",
"module": "build/esm/index.js",
3 changes: 1 addition & 2 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -16,8 +16,7 @@
],
"assignees": [
"@dyladan",
"@mayurkale22",
"@obecny"
"@vmarchaud"
],
"schedule": [
"before 3am on Friday"
37 changes: 37 additions & 0 deletions src/common/Attributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

/**
* Attributes is a map from string to attribute values.
*
* Note: only the own enumerable keys are counted as valid attribute keys.
*/
export interface Attributes {
[attributeKey: string]: AttributeValue | undefined;
}

/**
* Attribute values may be any non-nullish primitive value except an object.
*
* null or undefined attribute values are invalid and will result in undefined behavior.
*/
export type AttributeValue =
| string
| number
| boolean
| Array<null | undefined | string>
| Array<null | undefined | number>
| Array<null | undefined | boolean>;
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ export * from './baggage/types';
export { baggageEntryMetadataFromString } from './baggage/utils';
export * from './common/Exception';
export * from './common/Time';
export * from './common/Attributes';
export * from './diag';
export * from './propagation/TextMapPropagator';
export * from './trace/attributes';
@@ -33,8 +34,10 @@ export * from './trace/SpanOptions';
export * from './trace/status';
export * from './trace/trace_flags';
export * from './trace/trace_state';
export { createTraceState } from './trace/internal/utils';
export * from './trace/tracer_provider';
export * from './trace/tracer';
export * from './trace/tracer_options';

export {
isSpanContextValid,
7 changes: 6 additions & 1 deletion src/trace/NoopTracerProvider.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@

import { NoopTracer } from './NoopTracer';
import { Tracer } from './tracer';
import { TracerOptions } from './tracer_options';
import { TracerProvider } from './tracer_provider';

/**
@@ -25,7 +26,11 @@ import { TracerProvider } from './tracer_provider';
* All operations are no-op.
*/
export class NoopTracerProvider implements TracerProvider {
getTracer(_name?: string, _version?: string): Tracer {
getTracer(
_name?: string,
_version?: string,
_options?: TracerOptions
): Tracer {
return new NoopTracer();
}
}
8 changes: 5 additions & 3 deletions src/trace/ProxyTracer.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import { NoopTracer } from './NoopTracer';
import { Span } from './span';
import { SpanOptions } from './SpanOptions';
import { Tracer } from './tracer';
import { TracerOptions } from './tracer_options';

const NOOP_TRACER = new NoopTracer();

@@ -32,7 +33,8 @@ export class ProxyTracer implements Tracer {
constructor(
private _provider: TracerDelegator,
public readonly name: string,
public readonly version?: string
public readonly version?: string,
public readonly options?: TracerOptions
) {}

startSpan(name: string, options?: SpanOptions, context?: Context): Span {
@@ -58,7 +60,7 @@ export class ProxyTracer implements Tracer {
return this._delegate;
}

const tracer = this._provider.getDelegateTracer(this.name, this.version);
const tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);

if (!tracer) {
return NOOP_TRACER;
@@ -70,5 +72,5 @@ export class ProxyTracer implements Tracer {
}

export interface TracerDelegator {
getDelegateTracer(name: string, version?: string): Tracer | undefined;
getDelegateTracer(name: string, version?: string, options?: TracerOptions): Tracer | undefined;
}
15 changes: 10 additions & 5 deletions src/trace/ProxyTracerProvider.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import { Tracer } from './tracer';
import { TracerProvider } from './tracer_provider';
import { ProxyTracer } from './ProxyTracer';
import { NoopTracerProvider } from './NoopTracerProvider';
import { TracerOptions } from './tracer_options';

const NOOP_TRACER_PROVIDER = new NoopTracerProvider();

@@ -35,10 +36,10 @@ export class ProxyTracerProvider implements TracerProvider {
/**
* Get a {@link ProxyTracer}
*/
getTracer(name: string, version?: string): Tracer {
getTracer(name: string, version?: string, options?: TracerOptions): Tracer {
return (
this.getDelegateTracer(name, version) ??
new ProxyTracer(this, name, version)
this.getDelegateTracer(name, version, options) ??
new ProxyTracer(this, name, version, options)
);
}

@@ -53,7 +54,11 @@ export class ProxyTracerProvider implements TracerProvider {
this._delegate = delegate;
}

getDelegateTracer(name: string, version?: string): Tracer | undefined {
return this._delegate?.getTracer(name, version);
getDelegateTracer(
name: string,
version?: string,
options?: TracerOptions
): Tracer | undefined {
return this._delegate?.getTracer(name, version, options);
}
}
21 changes: 8 additions & 13 deletions src/trace/attributes.ts
Original file line number Diff line number Diff line change
@@ -14,19 +14,14 @@
* limitations under the License.
*/

export interface SpanAttributes {
[attributeKey: string]: SpanAttributeValue | undefined;
}
import { Attributes, AttributeValue } from '../common/Attributes';

/**
* Attribute values may be any non-nullish primitive value except an object.
*
* null or undefined attribute values are invalid and will result in undefined behavior.
* @deprecated please use {@link Attributes}
*/
export type SpanAttributes = Attributes;

/**
* @deprecated please use {@link AttributeValue}
*/
export type SpanAttributeValue =
| string
| number
| boolean
| Array<null | undefined | string>
| Array<null | undefined | number>
| Array<null | undefined | boolean>;
export type SpanAttributeValue = AttributeValue;
110 changes: 110 additions & 0 deletions src/trace/internal/tracestate-impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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 { TraceState } from '../trace_state';
import { validateKey, validateValue } from './tracestate-validators';

const MAX_TRACE_STATE_ITEMS = 32;
const MAX_TRACE_STATE_LEN = 512;
const LIST_MEMBERS_SEPARATOR = ',';
const LIST_MEMBER_KEY_VALUE_SPLITTER = '=';

/**
* TraceState must be a class and not a simple object type because of the spec
* requirement (https://www.w3.org/TR/trace-context/#tracestate-field).
*
* Here is the list of allowed mutations:
* - New key-value pair should be added into the beginning of the list
* - The value of any key can be updated. Modified keys MUST be moved to the
* beginning of the list.
*/
export class TraceStateImpl implements TraceState {
private _internalState: Map<string, string> = new Map();

constructor(rawTraceState?: string) {
if (rawTraceState) this._parse(rawTraceState);
}

set(key: string, value: string): TraceStateImpl {
// TODO: Benchmark the different approaches(map vs list) and
// use the faster one.
const traceState = this._clone();
if (traceState._internalState.has(key)) {
traceState._internalState.delete(key);
}
traceState._internalState.set(key, value);
return traceState;
}

unset(key: string): TraceStateImpl {
const traceState = this._clone();
traceState._internalState.delete(key);
return traceState;
}

get(key: string): string | undefined {
return this._internalState.get(key);
}

serialize(): string {
return this._keys()
.reduce((agg: string[], key) => {
agg.push(key + LIST_MEMBER_KEY_VALUE_SPLITTER + this.get(key));
return agg;
}, [])
.join(LIST_MEMBERS_SEPARATOR);
}

private _parse(rawTraceState: string) {
if (rawTraceState.length > MAX_TRACE_STATE_LEN) return;
this._internalState = rawTraceState
.split(LIST_MEMBERS_SEPARATOR)
.reverse() // Store in reverse so new keys (.set(...)) will be placed at the beginning
.reduce((agg: Map<string, string>, part: string) => {
const listMember = part.trim(); // Optional Whitespace (OWS) handling
const i = listMember.indexOf(LIST_MEMBER_KEY_VALUE_SPLITTER);
if (i !== -1) {
const key = listMember.slice(0, i);
const value = listMember.slice(i + 1, part.length);
if (validateKey(key) && validateValue(value)) {
agg.set(key, value);
} else {
// TODO: Consider to add warning log
}
}
return agg;
}, new Map());

// Because of the reverse() requirement, trunc must be done after map is created
if (this._internalState.size > MAX_TRACE_STATE_ITEMS) {
this._internalState = new Map(
Array.from(this._internalState.entries())
.reverse() // Use reverse same as original tracestate parse chain
.slice(0, MAX_TRACE_STATE_ITEMS)
);
}
}

private _keys(): string[] {
return Array.from(this._internalState.keys()).reverse();
}

private _clone(): TraceStateImpl {
const traceState = new TraceStateImpl();
traceState._internalState = new Map(this._internalState);
return traceState;
}
}
Loading