feat: browser support for exporter-trace-otlp-proto (#3208)

* add node & browser platform for exporter-trace-otlp-proto

* add browser support for proto base exporter

* add base browser class with xhr support

* add browser class for proto trace exporter

* slight tweaks to make it work

* send data as blob to avoid making sync xhr requests

* fix lint

* remove console.logs and add browser proto example

* cleanup and start adding tests

* Undo formatting changes

* exporter-trace-otlp-proto: fix compile errors

* Misc updates from review comments

* Adding changelog entry

* Reverting format changes not needed

* Moving the send function into the class for browser case.

* Adjust indentation to fix lint errors

* Remove template parameter that's not needed

* Apply review changes

* fix the import path

* Addressing lint errors

* Explicit imports for browser case

* More explicit exports

* Add missing exports

* Address lint issues with export statements

* Adding missing exports

* Adding missing export

* Using import from top level folder

* Trigger Build

* Update experimental/packages/exporter-trace-otlp-proto/test/browser/CollectorTraceExporter.test.ts

Co-authored-by: Marc Pichler <marcpi@edu.aau.at>

* Remove trailing comma

* Remove blank line to fix lint error

* Fixes based on testing opentelemetry-web/fetch-proto

* Add additional missing export

* Skip hex conversion of traceId for the protobuf

* Add esm/esnext builds for the proto packages

that will now be used for the browser case as well.

* Trigger Build

Co-authored-by: Santosh Cheler <scheler@cisco.com>
Co-authored-by: Santosh Cheler <santosh.cheler@gmail.com>
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Co-authored-by: Marc Pichler <marcpi@edu.aau.at>
This commit is contained in:
Purvi Kanal 2023-01-20 01:12:20 -05:00 committed by GitHub
parent 652d167531
commit 9589d541ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 623 additions and 29 deletions

View File

@ -24,6 +24,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
### :rocket: (Enhancement)
* feat(instrumentation-grpc): set net.peer.name and net.peer.port on client spans [#3430](https://github.com/open-telemetry/opentelemetry-js/pull/3430)
* feat(exporter-trace-otlp-proto): Add protobuf otlp trace exporter support for browser [#3208](https://github.com/open-telemetry/opentelemetry-js/pull/3208) @pkanal
### :bug: (Bug Fix)

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fetch Plugin Example</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
Example of using Web Tracer with Fetch plugin with console exporter and proto exporter
<script type="text/javascript" src="fetch-proto.js"></script>
<br/>
<button id="button1">Test</button>
</body>
</html>

View File

@ -0,0 +1,80 @@
const { context, trace } = require("@opentelemetry/api");
const { ConsoleSpanExporter, SimpleSpanProcessor} = require("@opentelemetry/sdk-trace-base");
const { WebTracerProvider } = require("@opentelemetry/sdk-trace-web");
const { FetchInstrumentation } = require("@opentelemetry/instrumentation-fetch");
const { ZoneContextManager } = require("@opentelemetry/context-zone");
const { B3Propagator } = require("@opentelemetry/propagator-b3");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const { OTLPTraceExporter: OTLPTraceExporterProto } = require("@opentelemetry/exporter-trace-otlp-proto");
const provider = new WebTracerProvider();
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(
new SimpleSpanProcessor(new OTLPTraceExporterProto())
);
provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
});
registerInstrumentations({
instrumentations: [
new FetchInstrumentation({
ignoreUrls: [/localhost:8090\/sockjs-node/],
propagateTraceHeaderCorsUrls: [
"https://cors-test.appspot.com/test",
"https://httpbin.org/get",
],
clearTimingResources: true,
}),
],
});
const webTracerWithZone = provider.getTracer("example-tracer-web");
const getData = (url) =>
fetch(url, {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
// example of keeping track of context between async operations
const prepareClickEvent = () => {
const url = "https://httpbin.org/get";
const element = document.getElementById("button1");
const onClick = () => {
const singleSpan = webTracerWithZone.startSpan("files-series-info");
context.with(trace.setSpan(context.active(), singleSpan), () => {
getData(url).then((_data) => {
trace
.getSpan(context.active())
.addEvent("fetching-single-span-completed");
singleSpan.end();
});
});
for (let i = 0, j = 5; i < j; i += 1) {
const span = webTracerWithZone.startSpan(`files-series-info-${i}`);
context.with(trace.setSpan(context.active(), span), () => {
getData(url).then((_data) => {
trace
.getSpan(context.active())
.addEvent(`fetching-span-${i}-completed`);
span.end();
});
});
}
};
element.addEventListener("click", onClick);
};
window.addEventListener("load", prepareClickEvent);

View File

@ -47,6 +47,7 @@
"@opentelemetry/core": "1.9.0",
"@opentelemetry/exporter-metrics-otlp-http": "0.35.0",
"@opentelemetry/exporter-trace-otlp-http": "0.35.0",
"@opentelemetry/exporter-trace-otlp-proto": "0.35.0",
"@opentelemetry/exporter-zipkin": "1.9.0",
"@opentelemetry/instrumentation": "0.35.0",
"@opentelemetry/instrumentation-fetch": "0.35.0",

View File

@ -12,6 +12,7 @@ const common = {
'xml-http-request': 'examples/xml-http-request/index.js',
fetchXhr: 'examples/fetchXhr/index.js',
fetchXhrB3: 'examples/fetchXhrB3/index.js',
'fetch-proto': 'examples/fetch-proto/index.js',
zipkin: 'examples/zipkin/index.js',
},
output: {
@ -41,7 +42,7 @@ const common = {
resolve: {
modules: [
path.resolve(directory),
'node_modules',
'node_modules'
],
extensions: ['.ts', '.js', '.jsx', '.json'],
},

View File

@ -12,6 +12,7 @@ const common = {
'xml-http-request': 'examples/xml-http-request/index.js',
fetchXhr: 'examples/fetchXhr/index.js',
fetchXhrB3: 'examples/fetchXhrB3/index.js',
"fetch-proto": "examples/fetch-proto/index.js",
zipkin: 'examples/zipkin/index.js',
},
output: {

View File

@ -0,0 +1,26 @@
/*!
* 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
*
* http://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.
*/
const karmaWebpackConfig = require('../../../karma.webpack');
const karmaBaseConfig = require('../../../karma.base');
module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig,
files: ['test/browser/index-webpack.ts'],
preprocessors: { 'test/browser/index-webpack.ts': ['webpack'] }
}))
};

View File

@ -3,18 +3,27 @@
"version": "0.35.0",
"description": "OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector using protobuf over HTTP",
"main": "build/src/index.js",
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"scripts": {
"prepublishOnly": "npm run compile",
"compile": "tsc --build",
"clean": "tsc --build --clean",
"compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'",
"test:browser": "nyc karma start --single-run",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc --build --watch",
"watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile",
"peer-api-check": "node ../../../scripts/peer-api-check.js",
@ -35,6 +44,12 @@
"node": ">=14"
},
"files": [
"build/esm/**/*.js",
"build/esm/**/*.js.map",
"build/esm/**/*.d.ts",
"build/esnext/**/*.js",
"build/esnext/**/*.js.map",
"build/esnext/**/*.d.ts",
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",

View File

@ -13,5 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './OTLPTraceExporter';
export { OTLPTraceExporter } from './platform';

View File

@ -0,0 +1,72 @@
/*
* 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 { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { getEnv, baggageUtils } from '@opentelemetry/core';
import {
OTLPExporterConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
} from '@opentelemetry/otlp-exporter-base';
import {
OTLPProtoExporterBrowserBase,
ServiceClientType,
} from '@opentelemetry/otlp-proto-exporter-base';
import {
createExportTraceServiceRequest,
IExportTraceServiceRequest,
} from '@opentelemetry/otlp-transformer';
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
/**
* Collector Trace Exporter for Web
*/
export class OTLPTraceExporter
extends OTLPProtoExporterBrowserBase<ReadableSpan, IExportTraceServiceRequest>
implements SpanExporter
{
constructor(config: OTLPExporterConfigBase = {}) {
super(config);
this._headers = Object.assign(
this._headers,
baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS
)
);
}
convert(spans: ReadableSpan[]): IExportTraceServiceRequest {
return createExportTraceServiceRequest(spans);
}
getDefaultUrl(config: OTLPExporterConfigBase): string {
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrl(
getEnv().OTEL_EXPORTER_OTLP_ENDPOINT,
DEFAULT_COLLECTOR_RESOURCE_PATH
)
: DEFAULT_COLLECTOR_URL;
}
getServiceClientType() {
return ServiceClientType.SPANS;
}
}

View File

@ -0,0 +1,16 @@
/*
* 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 { OTLPTraceExporter } from './OTLPTraceExporter';

View File

@ -0,0 +1,16 @@
/*
* 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 { OTLPTraceExporter } from './node';

View File

@ -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 { OTLPTraceExporter } from './OTLPTraceExporter';

View File

@ -0,0 +1,50 @@
/*
* 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 * as sinon from 'sinon';
import { OTLPTraceExporter } from '../../src/platform/browser/index';
describe('OTLPTraceExporter - web', () => {
let collectorTraceExporter: OTLPTraceExporter;
describe('constructor', () => {
let onInitSpy: any;
beforeEach(() => {
onInitSpy = sinon.stub(OTLPTraceExporter.prototype, 'onInit');
const collectorExporterConfig = {
hostname: 'foo',
url: 'http://foo.bar.com',
};
collectorTraceExporter = new OTLPTraceExporter(collectorExporterConfig);
});
afterEach(() => {
sinon.restore();
});
it('should create an instance', () => {
assert.ok(typeof collectorTraceExporter !== 'undefined');
});
it('should call onInit', () => {
assert.strictEqual(onInitSpy.callCount, 1);
});
it('should set hostname', () => {
assert.strictEqual(collectorTraceExporter.hostname, 'foo');
});
it('should set url', () => {
assert.strictEqual(collectorTraceExporter.url, 'http://foo.bar.com');
});
});
});

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
const testsContext = require.context('../browser', true, /test$/);
testsContext.keys().forEach(testsContext);
const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);

View File

@ -22,13 +22,13 @@ import * as http from 'http';
import * as sinon from 'sinon';
import { Stream, PassThrough } from 'stream';
import * as zlib from 'zlib';
import { OTLPTraceExporter } from '../src';
import { OTLPTraceExporter } from '../../src';
import {
ensureExportTraceServiceRequestIsSet,
ensureProtoSpanIsCorrect,
mockedReadableSpan,
MockedResponse,
} from './traceHelper';
} from '../traceHelper';
import {
CompressionAlgorithm,
OTLPExporterNodeConfigBase,

View File

@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.esm.json",
"compilerOptions": {
"outDir": "build/esm",
"rootDir": "src",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
}
]
}

View File

@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.esnext.json",
"compilerOptions": {
"outDir": "build/esnext",
"rootDir": "src",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"include": [
"src/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
}
]
}

View File

@ -13,7 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './OTLPExporterBase';
export * from './platform';
export * from './types';
export * from './util';
export { OTLPExporterBase } from './OTLPExporterBase';
export {
OTLPExporterError,
OTLPExporterConfigBase,
ExportServiceError,
} from './types';
export {
parseHeaders,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
configureExporterTimeout,
invalidTimeout,
} from './util';

View File

@ -14,4 +14,5 @@
* limitations under the License.
*/
export * from './OTLPExporterBrowserBase';
export { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';
export { sendWithXhr } from './util';

View File

@ -50,7 +50,7 @@ export function sendWithBeacon(
* @param onError
*/
export function sendWithXhr(
body: string,
body: string | Blob,
url: string,
headers: Record<string, string>,
exporterTimeout: number,

View File

@ -13,5 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './node';
export { OTLPExporterBrowserBase } from './browser';
export {
OTLPExporterNodeBase,
sendWithHttp,
createHttpAgent,
configureCompression,
OTLPExporterNodeConfigBase,
CompressionAlgorithm,
} from './node';
export { OTLPExporterBrowserBase, sendWithXhr } from './browser';

View File

@ -14,6 +14,6 @@
* limitations under the License.
*/
export * from './OTLPExporterNodeBase';
export * from './util';
export * from './types';
export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
export { sendWithHttp, createHttpAgent, configureCompression } from './util';
export { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';

View File

@ -3,18 +3,26 @@
"version": "0.35.0",
"description": "OpenTelemetry OTLP-HTTP-protobuf Exporter base (for internal use only)",
"main": "build/src/index.js",
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"scripts": {
"prepublishOnly": "npm run compile",
"compile": "npm run protos && tsc --build",
"clean": "tsc --build --clean",
"compile": "npm run protos && tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"protos": "npm run submodule && node scripts/protos.js",
"submodule": "git submodule sync --recursive && git submodule update --init --recursive",
"version": "node ../../../scripts/version-update.js",
"watch": "npm run protos && tsc -w",
"watch": "npm run protos && tsc -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"
},
@ -33,6 +41,12 @@
"node": ">=14"
},
"files": [
"build/esm/**/*.js",
"build/esm/**/*.js.map",
"build/esm/**/*.d.ts",
"build/esnext/**/*.js",
"build/esnext/**/*.js.map",
"build/esnext/**/*.d.ts",
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",

View File

@ -13,7 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { OTLPProtoExporterNodeBase } from './OTLPProtoExporterNodeBase';
export * from './types';
export * from './util';
export * from './platform';

View File

@ -0,0 +1,90 @@
/*
* 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';
import { ServiceClientType } from '../types';
import {
OTLPExporterBrowserBase as OTLPExporterBaseMain,
OTLPExporterError,
OTLPExporterConfigBase,
sendWithXhr,
} from '@opentelemetry/otlp-exporter-base';
import * as root from '../../generated/root';
interface ExportRequestType<T, R = T & { toJSON: () => unknown }> {
create(properties?: T): R;
encode(message: T, writer?: protobuf.Writer): protobuf.Writer;
decode(reader: protobuf.Reader | Uint8Array, length?: number): R;
}
/**
* Collector Exporter abstract base class
*/
export abstract class OTLPProtoExporterBrowserBase<
ExportItem,
ServiceRequest
> extends OTLPExporterBaseMain<ExportItem, ServiceRequest> {
constructor(config: OTLPExporterConfigBase = {}) {
super(config);
}
private _getExportRequestProto(
clientType: ServiceClientType
): ExportRequestType<ServiceRequest> {
if (clientType === ServiceClientType.SPANS) {
// eslint-disable-next-line
return root.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest as unknown as ExportRequestType<ServiceRequest>;
} else {
// eslint-disable-next-line
return root.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest as unknown as ExportRequestType<ServiceRequest>;
}
}
override send(
objects: ExportItem[],
onSuccess: () => void,
onError: (error: OTLPExporterError) => void
): void {
if (this._shutdownOnce.isCalled) {
diag.debug('Shutdown already started. Cannot send objects');
return;
}
const serviceRequest = this.convert(objects);
const exportRequestType = this._getExportRequestProto(
this.getServiceClientType()
);
const message = exportRequestType.create(serviceRequest);
if (message) {
const body = exportRequestType.encode(message).finish();
if (body) {
sendWithXhr(
new Blob([body], { type: 'application/x-protobuf' }),
this.url,
{ ...this._headers, 'Content-Type': 'application/x-protobuf' },
this.timeoutMillis,
onSuccess,
onError
);
}
} else {
onError(new OTLPExporterError('No proto'));
}
}
abstract getServiceClientType(): ServiceClientType;
}

View File

@ -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 { OTLPProtoExporterBrowserBase } from './OTLPProtoExporterBrowserBase';
export { ServiceClientType } from '../types';

View File

@ -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.
*/
export {
OTLPProtoExporterNodeBase,
ExportRequestType,
getExportRequestProto,
send,
} from './node';
export { OTLPProtoExporterBrowserBase } from './browser';
export { ServiceClientType } from './types';

View File

@ -15,7 +15,7 @@
*/
import { diag } from '@opentelemetry/api';
import { ServiceClientType } from './types';
import { ServiceClientType } from '../types';
import {
OTLPExporterNodeBase as OTLPExporterBaseMain,
CompressionAlgorithm,

View File

@ -0,0 +1,18 @@
/*
* 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 { OTLPProtoExporterNodeBase } from './OTLPProtoExporterNodeBase';
export { ExportRequestType, getExportRequestProto, send } from './util';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ServiceClientType } from './types';
import { ServiceClientType } from '../types';
import { OTLPProtoExporterNodeBase } from './OTLPProtoExporterNodeBase';
import {
CompressionAlgorithm,
@ -22,7 +22,7 @@ import {
sendWithHttp,
} from '@opentelemetry/otlp-exporter-base';
import type * as protobuf from 'protobufjs';
import * as root from './generated/root';
import * as root from '../../generated/root';
export interface ExportRequestType<T, R = T & { toJSON: () => unknown }> {
create(properties?: T): R;

View File

@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.base.esm.json",
"compilerOptions": {
"allowJs": true,
"outDir": "build/esm",
"rootDir": "src",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts",
"src/generated/*.js"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
}
]
}

View File

@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.base.esnext.json",
"compilerOptions": {
"allowJs": true,
"outDir": "build/esnext",
"rootDir": "src",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"include": [
"src/**/*.ts",
"src/generated/*.js",
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
}
]
}