Skip to content

Commit

Permalink
Merge branch 'main' into oc-shim-4-rim
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed May 17, 2023
2 parents fdd6daf + 17eca4c commit 2b8ec3b
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/peer-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
peer-api-check:
runs-on: ubuntu-latest
container:
image: node:18
image: node:20
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to experimental packages in this project will be documented

* feat(instrumentation): add ESM support for instrumentation. [#3698](https://github.com/open-telemetry/opentelemetry-js/pull/3698) @JamieDanielson, @pkanal, @vmarchaud, @lizthegrey, @bengl
* feat(otlp-trace-exporters): Add User-Agent header to OTLP trace exporters. [#3790](https://github.com/open-telemetry/opentelemetry-js/pull/3790) @JamieDanielson
* feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters. [#3806](https://github.com/open-telemetry/opentelemetry-js/pull/3806) @JamieDanielson
* feat(opencensus-shim): add OpenCensus trace shim [#3809](https://github.com/open-telemetry/opentelemetry-js/pull/3809) @aabmass

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,25 @@ import {
createExportMetricsServiceRequest,
IExportMetricsServiceRequest,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from './version';

const USER_AGENT = {
'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`,
};

class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase<
ResourceMetrics,
IExportMetricsServiceRequest
> {
constructor(config?: OTLPGRPCExporterConfigNode & OTLPMetricExporterOptions) {
super(config);
const headers = baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
);
const headers = {
...USER_AGENT,
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
};

this.metadata ||= new Metadata();
for (const [k, v] of Object.entries(headers)) {
this.metadata.set(k, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
IExportMetricsServiceRequest,
IResourceMetrics,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from '../src/version';

const metricsServiceProtoPath =
'opentelemetry/proto/collector/metrics/v1/metrics_service.proto';
Expand Down Expand Up @@ -314,6 +315,13 @@ describe('when configuring via environment', () => {
);
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should include user agent in header', () => {
const collectorExporter = new OTLPMetricExporter();
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('User-Agent'),
[`OTel-OTLP-Exporter-JavaScript/${VERSION}`]
);
});
it('should override global headers config with signal headers defined via env', () => {
const metadata = new grpc.Metadata();
metadata.set('foo', 'bar');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ import {
createExportMetricsServiceRequest,
IExportMetricsServiceRequest,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from '../../version';

const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const USER_AGENT = {
'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`,
};

class OTLPExporterNodeProxy extends OTLPExporterNodeBase<
ResourceMetrics,
IExportMetricsServiceRequest
> {
constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) {
super(config);
this.headers = Object.assign(
this.headers,
baggageUtils.parseKeyPairsIntoRecord(
this.headers = {
...this.headers,
...USER_AGENT,
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
)
);
),
};
}

convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
OTLPExporterNodeConfigBase,
} from '@opentelemetry/otlp-exporter-base';
import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';
import { VERSION } from '../../src/version';

let fakeRequest: PassThrough;

Expand Down Expand Up @@ -188,6 +189,13 @@ describe('OTLPMetricExporter - node with json over http', () => {
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'bar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should include user agent in header', () => {
const collectorExporter = new OTLPMetricExporter();
assert.strictEqual(
collectorExporter._otlpExporter.headers['User-Agent'],
`OTel-OTLP-Exporter-JavaScript/${VERSION}`
);
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ import {
createExportMetricsServiceRequest,
IExportMetricsServiceRequest,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from './version';

const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const USER_AGENT = {
'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`,
};

class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase<
ResourceMetrics,
IExportMetricsServiceRequest
> {
constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) {
super(config);
this.headers = Object.assign(
this.headers,
baggageUtils.parseKeyPairsIntoRecord(
this.headers = {
...this.headers,
...USER_AGENT,
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
)
);
),
};
}

convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp-
import { Stream, PassThrough } from 'stream';
import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';
import { VERSION } from '../src/version';

let fakeRequest: PassThrough;

Expand All @@ -60,6 +61,16 @@ describe('OTLPMetricExporter - node with proto over http', () => {
sinon.restore();
});

describe('default behavior for headers', () => {
const collectorExporter = new OTLPMetricExporter();
it('should include user agent in header', () => {
assert.strictEqual(
collectorExporter._otlpExporter.headers['User-Agent'],
`OTel-OTLP-Exporter-JavaScript/${VERSION}`
);
});
});

describe('when configuring via environment', () => {
const envSource = process.env;
it('should use url defined in env that ends with root path and append version and signal path', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/semver": "7.3.9",
"@types/sinon": "10.0.13",
"@types/superagent": "4.1.13",
"axios": "0.24.0",
"axios": "1.4.0",
"codecov": "3.8.3",
"mocha": "10.0.0",
"nock": "13.0.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Packages', () => {
const result = await httpPackage.get(urlparsed.href!);
if (!resHeaders) {
const res = result as AxiosResponse<unknown>;
resHeaders = res.headers;
resHeaders = res.headers as any;
}
const spans = memoryExporter.getFinishedSpans();
const span = spans[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Packages', () => {
const result = await httpPackage.get(urlparsed.href!);
if (!resHeaders) {
const res = result as AxiosResponse<unknown>;
resHeaders = res.headers;
resHeaders = res.headers as any;
}
const spans = memoryExporter.getFinishedSpans();
const span = spans[0];
Expand Down
7 changes: 3 additions & 4 deletions experimental/packages/shim-opencensus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/core": "1.13.0",
"@opentelemetry/context-async-hooks": "1.13.0",
"@opentelemetry/sdk-trace-base": "1.13.0",
"@opencensus/core": "0.1.0",
Expand All @@ -64,9 +63,9 @@
"@opentelemetry/api": "^1.0.0"
},
"dependencies": {
"@opentelemetry/core": "^1.0.0",
"semver": "^7.3.5",
"require-in-the-middle": "^7.1.0"
"@opentelemetry/core": "1.13.0",
"require-in-the-middle": "^7.0.0",
"semver": "^7.3.5"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/shim-opencensus",
"sideEffects": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@opentelemetry/context-async-hooks": "1.13.0",
"@opentelemetry/core": "1.13.0",
"@opentelemetry/sdk-trace-base": "1.13.0",
"axios": "0.24.0",
"axios": "1.4.0",
"body-parser": "1.19.0",
"express": "4.17.3"
},
Expand Down

0 comments on commit 2b8ec3b

Please sign in to comment.