Skip to content

Commit

Permalink
Merge branch 'main' into map-input-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeavila94 authored Jan 9, 2024
2 parents 6ebca8e + ae0a3c5 commit 8e5c24e
Show file tree
Hide file tree
Showing 33 changed files with 292 additions and 107 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: javascript

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
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
9 changes: 9 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ All notable changes to experimental packages in this project will be documented

### :boom: Breaking Change

* fix(exporter-logs-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati
* fix(exporter-logs-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati
* fix(exporter-trace-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati
* fix(exporter-trace-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4351) @Vunovati

### :rocket: (Enhancement)

### :bug: (Bug Fix)

* fix(instrumentation): use caret range on import-in-the-middle [#4380](https://github.com/open-telemetry/opentelemetry-js/pull/4380) @pichlermarc
* fix(instrumentation): do not import 'path' in browser runtimes [#4378](https://github.com/open-telemetry/opentelemetry-js/pull/4378) @pichlermarc
* Fixes a bug where bundling for web would fail due to `InstrumentationNodeModuleDefinition` importing `path`

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export class OTLPLogExporter
timeoutMillis: getEnv().OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
...config,
});
this.headers = {
...this.headers,
...baggageUtils.parseKeyPairsIntoRecord(
this.headers = Object.assign(
this.headers,
baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS
),
};
config.headers
);
}

convert(logRecords: ReadableLogRecord[]): IExportLogsServiceRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ describe('OTLPLogExporter', () => {
delete envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS;
delete envSource.OTEL_EXPORTER_OTLP_LOGS_TIMEOUT;
});

it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPLogExporter({
headers: {
foo: 'constructor',
},
});
assert.strictEqual(collectorExporter.headers.foo, 'constructor');
assert.strictEqual(collectorExporter.headers.bar, 'foo');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
});

describe('getDefaultUrl', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class OTLPLogExporter
this.headers,
baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS
)
),
config.headers
);
}
convert(logs: ReadableLogRecord[]): IExportLogsServiceRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ describe('OTLPLogExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = '';
});
it('should override url defined in env with url defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
const constructorDefinedEndpoint = 'http://constructor/v1/logs';
const collectorExporter = new OTLPLogExporter({
url: constructorDefinedEndpoint,
});
assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should add root path when signal url defined in env contains no path and no root path', () => {
envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPLogExporter();
Expand Down Expand Up @@ -143,6 +152,17 @@ describe('OTLPLogExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPLogExporter({
headers: {
foo: 'constructor',
},
});
assert.strictEqual(collectorExporter.headers.foo, 'constructor');
assert.strictEqual(collectorExporter.headers.bar, 'foo');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
});

describe('export', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class OTLPTraceExporter
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS
),
...config.headers,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ describe('OTLPTraceExporter - node with json over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should override url defined in env with url defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
const constructorDefinedEndpoint = 'http://constructor/v1/traces';
const collectorExporter = new OTLPTraceExporter({
url: constructorDefinedEndpoint,
});
assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should add root path when signal url defined in env contains no path and no root path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
Expand Down Expand Up @@ -177,6 +186,17 @@ describe('OTLPTraceExporter - node with json over http', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPTraceExporter({
headers: {
foo: 'constructor',
},
});
assert.strictEqual(collectorExporter.headers.foo, 'constructor');
assert.strictEqual(collectorExporter.headers.bar, 'foo');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should use compression defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_COMPRESSION = 'gzip';
const collectorExporter = new OTLPTraceExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class OTLPTraceExporter
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS
),
...config.headers,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ describe('OTLPTraceExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should override url defined in env with url defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
const constructorDefinedEndpoint = 'http://constructor/v1/traces';
const collectorExporter = new OTLPTraceExporter({
url: constructorDefinedEndpoint,
});
assert.strictEqual(collectorExporter.url, constructorDefinedEndpoint);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should add root path when signal url defined in env contains no path and no root path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
Expand Down Expand Up @@ -155,6 +164,17 @@ describe('OTLPTraceExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPTraceExporter({
headers: {
foo: 'constructor',
},
});
assert.strictEqual(collectorExporter.headers.foo, 'constructor');
assert.strictEqual(collectorExporter.headers.bar, 'foo');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
});

describe('export', () => {
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { InstrumentationModuleFile } from './types';
import { normalize } from 'path';
import { normalize } from './platform/index';

export class InstrumentationNodeModuleFile<T>
implements InstrumentationModuleFile<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/

export { InstrumentationBase } from './instrumentation';
export { normalize } from './noop-normalize';
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { diag } from '@opentelemetry/api';

/**
* Placeholder normalize function to replace the node variant in browser runtimes,
* this should never be called and will perform a no-op and warn if it is called regardless.
*
* This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/4373 until the instrumentation
* package can be made node-only.
*
* @param path input path
* @return unmodified path
* @internal
*/
export function normalize(path: string): string {
diag.warn(
'Path normalization is not implemented for this platform. To silence this warning, ensure no node-specific instrumentations are loaded, and node-specific types (e.g. InstrumentationNodeModuleFile), are not used in a browser context)'
);
return path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export { InstrumentationBase } from './node';
export { InstrumentationBase, normalize } from './node';
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
* limitations under the License.
*/
export { InstrumentationBase } from './instrumentation';
export { normalize } from './normalize';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/

export { normalize } from 'path';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 * as assert from 'assert';
import { normalize } from '../../src/platform/browser';

describe('noop-normalize', function () {
it('should not normalize input', function () {
assert.strictEqual(normalize('/tmp/foo/../bar'), '/tmp/foo/../bar');
});
});
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,
};
}
Loading

0 comments on commit 8e5c24e

Please sign in to comment.