Skip to content

Commit

Permalink
Merge branch 'main' into implement_sugared_tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Dec 20, 2023
2 parents 4f21c7b + f4b681d commit 98d3036
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 97 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
cache: 'npm'
cache-dependency-path: |
package-lock.json
node-version: '18'
node-version: '20'

- name: Install and Build 🔧
run: |
Expand All @@ -29,8 +29,10 @@ jobs:
NODE_OPTIONS: --max-old-space-size=6144

- name: Deploy Documentation 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
uses: JamesIves/github-pages-deploy-action@releases/v4
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: docs # The folder the action should deploy.
branch: gh-pages # The branch the action should deploy to.
folder: docs # The folder the action should deploy.
# ensure we don't override benchmark data
clean-exclude: |
benchmarks/**
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* perf(otlp-transformer): skip unnecessary base64 encode of span contexts [#4343](https://github.com/open-telemetry/opentelemetry-js/pull/4343) @seemk
* feat(sdk-trace-base): improve log messages when dropping span events [#4223](https://github.com/open-telemetry/opentelemetry-js/pull/4223) @mkubliniak

### :bug: (Bug Fix)
Expand Down
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

fix(instrumentation): use caret range on import-in-the-middle [#4380](https://github.com/open-telemetry/opentelemetry-js/pull/4380) @pichlermarc

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"dependencies": {
"@types/shimmer": "^1.0.2",
"import-in-the-middle": "1.7.1",
"import-in-the-middle": "^1.7.2",
"require-in-the-middle": "^7.1.1",
"semver": "^7.5.2",
"shimmer": "^1.2.1"
Expand Down
20 changes: 11 additions & 9 deletions experimental/packages/otlp-transformer/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { OtlpEncodingOptions, Fixed64, LongBits } from './types';
import { HrTime } from '@opentelemetry/api';
import { hexToBase64, hrTimeToNanoseconds } from '@opentelemetry/core';
import { hexToBinary, hrTimeToNanoseconds } from '@opentelemetry/core';

const NANOSECONDS = BigInt(1_000_000_000);

Expand Down Expand Up @@ -44,10 +44,12 @@ const encodeTimestamp =
typeof BigInt !== 'undefined' ? encodeAsString : hrTimeToNanoseconds;

export type HrTimeEncodeFunction = (hrTime: HrTime) => Fixed64;
export type SpanContextEncodeFunction = (spanContext: string) => string;
export type SpanContextEncodeFunction = (
spanContext: string
) => string | Uint8Array;
export type OptionalSpanContextEncodeFunction = (
spanContext: string | undefined
) => string | undefined;
) => string | Uint8Array | undefined;

export interface Encoder {
encodeHrTime: HrTimeEncodeFunction;
Expand All @@ -59,15 +61,15 @@ function identity<T>(value: T): T {
return value;
}

function optionalHexToBase64(str: string | undefined): string | undefined {
function optionalHexToBinary(str: string | undefined): Uint8Array | undefined {
if (str === undefined) return undefined;
return hexToBase64(str);
return hexToBinary(str);
}

const DEFAULT_ENCODER: Encoder = {
encodeHrTime: encodeAsLongBits,
encodeSpanContext: hexToBase64,
encodeOptionalSpanContext: optionalHexToBase64,
encodeSpanContext: hexToBinary,
encodeOptionalSpanContext: optionalHexToBinary,
};

export function getOtlpEncoder(options?: OtlpEncodingOptions): Encoder {
Expand All @@ -79,7 +81,7 @@ export function getOtlpEncoder(options?: OtlpEncodingOptions): Encoder {
const useHex = options.useHex ?? false;
return {
encodeHrTime: useLongBits ? encodeAsLongBits : encodeTimestamp,
encodeSpanContext: useHex ? identity : hexToBase64,
encodeOptionalSpanContext: useHex ? identity : optionalHexToBase64,
encodeSpanContext: useHex ? identity : hexToBinary,
encodeOptionalSpanContext: useHex ? identity : optionalHexToBinary,
};
}
4 changes: 2 additions & 2 deletions experimental/packages/otlp-transformer/src/logs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export interface ILogRecord {
flags?: number;

/** LogRecord traceId */
traceId?: string;
traceId?: string | Uint8Array;

/** LogRecord spanId */
spanId?: string;
spanId?: string | Uint8Array;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions experimental/packages/otlp-transformer/src/metrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ export interface IExemplar {
asInt?: number;

/** Exemplar spanId */
spanId?: string;
spanId?: string | Uint8Array;

/** Exemplar traceId */
traceId?: string;
traceId?: string | Uint8Array;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions experimental/packages/otlp-transformer/src/trace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ export interface IScopeSpans {
/** Properties of a Span. */
export interface ISpan {
/** Span traceId */
traceId: string;
traceId: string | Uint8Array;

/** Span spanId */
spanId: string;
spanId: string | Uint8Array;

/** Span traceState */
traceState?: string | null;

/** Span parentSpanId */
parentSpanId?: string;
parentSpanId?: string | Uint8Array;

/** Span name */
name: string;
Expand Down Expand Up @@ -181,10 +181,10 @@ export interface IEvent {
/** Properties of a Link. */
export interface ILink {
/** Link traceId */
traceId: string;
traceId: string | Uint8Array;

/** Link spanId */
spanId: string;
spanId: string | Uint8Array;

/** Link traceState */
traceState?: string;
Expand Down
12 changes: 6 additions & 6 deletions experimental/packages/otlp-transformer/test/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { hexToBase64 } from '@opentelemetry/core';
import { hexToBinary } from '@opentelemetry/core';
import { getOtlpEncoder } from '../src';
import { toAnyValue } from '../src/common/internal';
import * as assert from 'assert';
Expand Down Expand Up @@ -70,19 +70,19 @@ describe('common', () => {
});

describe('otlp encoder', () => {
it('defaults to long timestamps and base64 encoding given no options', () => {
it('defaults to long timestamps and binary encoding given no options', () => {
const encoder = getOtlpEncoder();
assert.deepStrictEqual(encoder.encodeHrTime([1697978649, 99870675]), {
low: 3352011219,
high: 395341461,
});
assert.deepStrictEqual(
encoder.encodeSpanContext(traceId),
hexToBase64(traceId)
hexToBinary(traceId)
);
assert.deepStrictEqual(
encoder.encodeOptionalSpanContext(spanId),
hexToBase64(spanId)
hexToBinary(spanId)
);
assert.deepStrictEqual(
encoder.encodeOptionalSpanContext(undefined),
Expand All @@ -98,11 +98,11 @@ describe('common', () => {
});
assert.deepStrictEqual(
encoder.encodeSpanContext(traceId),
hexToBase64(traceId)
hexToBinary(traceId)
);
assert.deepStrictEqual(
encoder.encodeOptionalSpanContext(spanId),
hexToBase64(spanId)
hexToBinary(spanId)
);
assert.deepStrictEqual(
encoder.encodeOptionalSpanContext(undefined),
Expand Down
6 changes: 3 additions & 3 deletions experimental/packages/otlp-transformer/test/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { HrTime, TraceFlags } from '@opentelemetry/api';
import { InstrumentationScope, hexToBase64 } from '@opentelemetry/core';
import { InstrumentationScope, hexToBinary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import {
Expand All @@ -28,8 +28,8 @@ import { SeverityNumber } from '@opentelemetry/api-logs';
function createExpectedLogJson(useHex: boolean): IExportLogsServiceRequest {
const traceId = useHex
? '00000000000000000000000000000001'
: hexToBase64('00000000000000000000000000000001');
const spanId = useHex ? '0000000000000002' : hexToBase64('0000000000000002');
: hexToBinary('00000000000000000000000000000001');
const spanId = useHex ? '0000000000000002' : hexToBinary('0000000000000002');

return {
resourceLogs: [
Expand Down
12 changes: 6 additions & 6 deletions experimental/packages/otlp-transformer/test/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { SpanKind, SpanStatusCode, TraceFlags } from '@opentelemetry/api';
import { TraceState, hexToBase64 } from '@opentelemetry/core';
import { TraceState, hexToBinary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
Expand All @@ -41,17 +41,17 @@ function createExpectedSpanJson(options: OtlpEncodingOptions) {

const traceId = useHex
? '00000000000000000000000000000001'
: hexToBase64('00000000000000000000000000000001');
const spanId = useHex ? '0000000000000002' : hexToBase64('0000000000000002');
: hexToBinary('00000000000000000000000000000001');
const spanId = useHex ? '0000000000000002' : hexToBinary('0000000000000002');
const parentSpanId = useHex
? '0000000000000001'
: hexToBase64('0000000000000001');
: hexToBinary('0000000000000001');
const linkSpanId = useHex
? '0000000000000003'
: hexToBase64('0000000000000003');
: hexToBinary('0000000000000003');
const linkTraceId = useHex
? '00000000000000000000000000000002'
: hexToBase64('00000000000000000000000000000002');
: hexToBinary('00000000000000000000000000000002');

return {
resourceSpans: [
Expand Down
39 changes: 24 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98d3036

Please sign in to comment.