@opentelemetry/otlp-grpc-exporter-base 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/src/OTLPGRPCExporterNodeBase.js +1 -2
- package/build/src/OTLPGRPCExporterNodeBase.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/types.js.map +1 -1
- package/build/src/util.js +10 -4
- package/build/src/util.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
[![NPM Published Version][npm-img]][npm-url]
|
|
4
4
|
[![Apache License][license-image]][license-image]
|
|
5
5
|
|
|
6
|
+
**Note: This package is intended for internal use only.**
|
|
7
|
+
|
|
6
8
|
**Note: This is an experimental package under active development. New releases may include breaking changes.**
|
|
7
9
|
|
|
8
10
|
This module provides a gRPC exporter base for Node.js (browsers not supported) to be used with [opentelemetry-collector][opentelemetry-collector-url].
|
|
@@ -42,8 +42,7 @@ class OTLPGRPCExporterNodeBase extends otlp_exporter_base_1.OTLPExporterBase {
|
|
|
42
42
|
_sendPromise(objects, onSuccess, onError) {
|
|
43
43
|
const promise = new Promise((resolve, reject) => {
|
|
44
44
|
this._send(this, objects, resolve, reject);
|
|
45
|
-
})
|
|
46
|
-
.then(onSuccess, onError);
|
|
45
|
+
}).then(onSuccess, onError);
|
|
47
46
|
this._sendingPromises.push(promise);
|
|
48
47
|
const popPromise = () => {
|
|
49
48
|
const index = this._sendingPromises.indexOf(promise);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OTLPGRPCExporterNodeBase.js","sourceRoot":"","sources":["../../src/OTLPGRPCExporterNodeBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,2CAA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AAI,CAAC,aAAa,EAAE;YACtB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;SAC5B;IACH,CAAC;CAKF;AAzFD,4DAyFC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag } from '@opentelemetry/api';\nimport { Metadata } from '@grpc/grpc-js';\nimport {\n OTLPGRPCExporterConfigNode,\n GRPCQueueItem,\n ServiceClientType,\n} from './types';\nimport { ServiceClient } from './types';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { configureCompression, GrpcCompressionAlgorithm } from './util';\nimport {\n OTLPExporterBase,\n OTLPExporterError,\n} from '@opentelemetry/otlp-exporter-base';\n\n/**\n * OTLP Exporter abstract base class\n */\nexport abstract class OTLPGRPCExporterNodeBase<\n ExportItem,\n ServiceRequest\n> extends OTLPExporterBase<\n OTLPGRPCExporterConfigNode,\n ExportItem,\n ServiceRequest\n> {\n grpcQueue: GRPCQueueItem<ExportItem>[] = [];\n metadata?: Metadata;\n serviceClient?: ServiceClient = undefined;\n private _send!: Function;\n compression: GrpcCompressionAlgorithm;\n\n constructor(config: OTLPGRPCExporterConfigNode = {}) {\n super(config);\n if (config.headers) {\n diag.warn('Headers cannot be set when using grpc');\n }\n const headers = baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n );\n this.metadata = config.metadata || new Metadata();\n for (const [k, v] of Object.entries(headers)) {\n this.metadata.set(k, v);\n }\n this.compression = configureCompression(config.compression);\n }\n\n private _sendPromise(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void {\n const promise = new Promise<void>((resolve, reject) => {\n this._send(this, objects, resolve, reject);\n }).then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n onInit(config: OTLPGRPCExporterConfigNode): void {\n // defer to next tick and lazy load to avoid loading grpc too early\n // and making this impossible to be instrumented\n setImmediate(() => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { onInit } = require('./util');\n onInit(this, config);\n });\n }\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n if (!this._send) {\n // defer to next tick and lazy load to avoid loading grpc too early\n // and making this impossible to be instrumented\n setImmediate(() => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { send } = require('./util');\n this._send = send;\n\n this._sendPromise(objects, onSuccess, onError);\n });\n } else {\n this._sendPromise(objects, onSuccess, onError);\n }\n }\n\n onShutdown(): void {\n if (this.serviceClient) {\n this.serviceClient.close();\n }\n }\n\n abstract getServiceProtoPath(): string;\n abstract getServiceClientType(): ServiceClientType;\n abstract getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string;\n}\n"]}
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './OTLPGRPCExporterNodeBase';
|
|
2
2
|
export { ServiceClientType, OTLPGRPCExporterConfigNode } from './types';
|
|
3
|
-
export { DEFAULT_COLLECTOR_URL, validateAndNormalizeUrl, GrpcCompressionAlgorithm } from './util';
|
|
3
|
+
export { DEFAULT_COLLECTOR_URL, validateAndNormalizeUrl, GrpcCompressionAlgorithm, } from './util';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;AAEH,6DAA2C;AAC3C,iCAAwE;AAA/D,0GAAA,iBAAiB,OAAA;AAC1B,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;AAEH,6DAA2C;AAC3C,iCAAwE;AAA/D,0GAAA,iBAAiB,OAAA;AAC1B,+BAIgB;AAHd,6GAAA,qBAAqB,OAAA;AACrB,+GAAA,uBAAuB,OAAA;AACvB,gHAAA,wBAAwB,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './OTLPGRPCExporterNodeBase';\nexport { ServiceClientType, OTLPGRPCExporterConfigNode } from './types';\nexport {\n DEFAULT_COLLECTOR_URL,\n validateAndNormalizeUrl,\n GrpcCompressionAlgorithm,\n} from './util';\n"]}
|
package/build/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAwCH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,2DAAK,CAAA;IACL,+DAAO,CAAA;AACT,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as grpc from '@grpc/grpc-js';\nimport {\n CompressionAlgorithm,\n OTLPExporterConfigBase,\n OTLPExporterError,\n} from '@opentelemetry/otlp-exporter-base';\n\n/**\n * Queue item to be used to save temporary spans/metrics in case the GRPC service\n * hasn't been fully initialized yet\n */\nexport interface GRPCQueueItem<ExportedItem> {\n objects: ExportedItem[];\n onSuccess: () => void;\n onError: (error: OTLPExporterError) => void;\n}\n\n/**\n * Service Client for sending spans or metrics\n */\nexport interface ServiceClient extends grpc.Client {\n export: (\n request: any,\n metadata: grpc.Metadata,\n options: grpc.CallOptions,\n callback: Function\n ) => {};\n}\n\n/**\n * OTLP Exporter Config for Node\n */\nexport interface OTLPGRPCExporterConfigNode extends OTLPExporterConfigBase {\n credentials?: grpc.ChannelCredentials;\n metadata?: grpc.Metadata;\n compression?: CompressionAlgorithm;\n}\n\nexport enum ServiceClientType {\n SPANS,\n METRICS,\n}\n"]}
|
package/build/src/util.js
CHANGED
|
@@ -41,7 +41,9 @@ function onInit(collector, config) {
|
|
|
41
41
|
})
|
|
42
42
|
.then(packageDefinition => {
|
|
43
43
|
const packageObject = grpc.loadPackageDefinition(packageDefinition);
|
|
44
|
-
const options = {
|
|
44
|
+
const options = {
|
|
45
|
+
'grpc.default_compression_algorithm': collector.compression,
|
|
46
|
+
};
|
|
45
47
|
if (collector.getServiceClientType() === types_1.ServiceClientType.SPANS) {
|
|
46
48
|
collector.serviceClient =
|
|
47
49
|
new packageObject.opentelemetry.proto.collector.trace.v1.TraceService(collector.url, credentials, options);
|
|
@@ -110,7 +112,8 @@ function configureSecurity(credentials, endpoint) {
|
|
|
110
112
|
else if (endpoint.startsWith('https://')) {
|
|
111
113
|
insecure = false;
|
|
112
114
|
}
|
|
113
|
-
else if (endpoint.startsWith('http://') ||
|
|
115
|
+
else if (endpoint.startsWith('http://') ||
|
|
116
|
+
endpoint === exports.DEFAULT_COLLECTOR_URL) {
|
|
114
117
|
insecure = true;
|
|
115
118
|
}
|
|
116
119
|
else {
|
|
@@ -209,8 +212,11 @@ function configureCompression(compression) {
|
|
|
209
212
|
return toGrpcCompression(compression);
|
|
210
213
|
}
|
|
211
214
|
else {
|
|
212
|
-
const definedCompression = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||
|
|
213
|
-
|
|
215
|
+
const definedCompression = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||
|
|
216
|
+
(0, core_1.getEnv)().OTEL_EXPORTER_OTLP_COMPRESSION;
|
|
217
|
+
return definedCompression === 'gzip'
|
|
218
|
+
? GrpcCompressionAlgorithm.GZIP
|
|
219
|
+
: GrpcCompressionAlgorithm.NONE;
|
|
214
220
|
}
|
|
215
221
|
}
|
|
216
222
|
exports.configureCompression = configureCompression;
|
package/build/src/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,sCAAsC;AACtC,kDAAkD;AAClD,4CAA0C;AAC1C,8CAAiE;AACjE,6BAA6B;AAE7B,6BAA0B;AAC1B,yBAAyB;AACzB,mCAAwF;AACxF,0EAAgH;AAEnG,QAAA,qBAAqB,GAAG,uBAAuB,CAAC;AAE7D,SAAgB,MAAM,CACpB,SAA+D,EAC/D,MAAkC;IAElC,SAAS,CAAC,SAAS,GAAG,EA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CAAC,4CAA4C;QACrD,IAAA,aAAM,GAAE,CAAC,qCAAqC,CAAC;IAEjD,IAAI,WAAW,EAAE;QACf,IAAI;YACF,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;SAClE;QAAC,WAAM;YACN,UAAI,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;YAC1D,OAAO,SAAS,CAAC;SAClB;KACF;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAiC;IAC1D,IAAI,WAAW,KAAK,yCAAoB,CAAC,IAAI;QAC3C,OAAO,wBAAwB,CAAC,IAAI,CAAC;SAClC,IAAI,WAAW,KAAK,yCAAoB,CAAC,IAAI;QAChD,OAAO,wBAAwB,CAAC,IAAI,CAAC;IACvC,OAAO,wBAAwB,CAAC,IAAI,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,uEAAQ,CAAA;IACR,uEAAQ,CAAA;AACV,CAAC,EAHW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAGnC;AAED,SAAgB,oBAAoB,CAAC,WAA6C;IAChF,IAAI,WAAW,EAAE;QACf,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;SAAM;QACL,MAAM,kBAAkB,GAAG,IAAA,aAAM,GAAE,CAAC,qCAAqC,IAAI,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QAErH,OAAO,kBAAkB,KAAK,MAAM,CAAC,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC;KACtG;AACH,CAAC;AARD,oDAQC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as grpc from '@grpc/grpc-js';\nimport * as protoLoader from '@grpc/proto-loader';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, globalErrorHandler } from '@opentelemetry/core';\nimport * as path from 'path';\nimport { OTLPGRPCExporterNodeBase } from './OTLPGRPCExporterNodeBase';\nimport { URL } from 'url';\nimport * as fs from 'fs';\nimport { GRPCQueueItem, OTLPGRPCExporterConfigNode, ServiceClientType, } from './types';\nimport { CompressionAlgorithm, ExportServiceError, OTLPExporterError } from '@opentelemetry/otlp-exporter-base';\n\nexport const DEFAULT_COLLECTOR_URL = 'http://localhost:4317';\n\nexport function onInit<ExportItem, ServiceRequest>(\n collector: OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest>,\n config: OTLPGRPCExporterConfigNode\n): void {\n collector.grpcQueue = [];\n\n const credentials: grpc.ChannelCredentials = configureSecurity(config.credentials, collector.getUrlFromConfig(config));\n\n const includeDirs = [path.resolve(__dirname, '..', 'protos')];\n\n protoLoader\n .load(collector.getServiceProtoPath(), {\n keepCase: false,\n longs: String,\n enums: String,\n defaults: true,\n oneofs: true,\n includeDirs,\n })\n .then(packageDefinition => {\n const packageObject: any = grpc.loadPackageDefinition(packageDefinition);\n\n const options = { 'grpc.default_compression_algorithm': collector.compression };\n\n if (collector.getServiceClientType() === ServiceClientType.SPANS) {\n collector.serviceClient =\n new packageObject.opentelemetry.proto.collector.trace.v1.TraceService(\n collector.url,\n credentials,\n options,\n );\n } else {\n collector.serviceClient =\n new packageObject.opentelemetry.proto.collector.metrics.v1.MetricsService(\n collector.url,\n credentials,\n options,\n );\n }\n\n if (collector.grpcQueue.length > 0) {\n const queue = collector.grpcQueue.splice(0);\n queue.forEach((item: GRPCQueueItem<ExportItem>) => {\n collector.send(item.objects, item.onSuccess, item.onError);\n });\n }\n })\n .catch(err => {\n globalErrorHandler(err);\n });\n}\n\nexport function send<ExportItem, ServiceRequest>(\n collector: OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest>,\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n if (collector.serviceClient) {\n const serviceRequest = collector.convert(objects);\n const deadline = Date.now() + collector.timeoutMillis;\n\n collector.serviceClient.export(\n serviceRequest,\n collector.metadata || new grpc.Metadata(),\n { deadline: deadline },\n (err: ExportServiceError) => {\n if (err) {\n diag.error('Service request', serviceRequest);\n onError(err);\n } else {\n diag.debug('Objects sent');\n onSuccess();\n }\n }\n );\n } else {\n collector.grpcQueue.push({\n objects,\n onSuccess,\n onError,\n });\n }\n}\n\nexport function validateAndNormalizeUrl(url: string): string {\n const hasProtocol = url.match(/^([\\w]{1,8}):\\/\\//);\n if (!hasProtocol) {\n url = `https://${url}`;\n }\n const target = new URL(url);\n if (target.pathname && target.pathname !== '/') {\n diag.warn(\n 'URL path should not be set when using grpc, the path part of the URL will be ignored.'\n );\n }\n if (target.protocol !== '' && !target.protocol?.match(/^(http)s?:$/)) {\n diag.warn(\n 'URL protocol should be http(s)://. Using http://.'\n );\n }\n return target.host;\n}\n\nexport function configureSecurity(credentials: grpc.ChannelCredentials | undefined, endpoint: string):\n grpc.ChannelCredentials {\n\n let insecure: boolean;\n\n if (credentials) {\n return credentials;\n } else if (endpoint.startsWith('https://')) {\n insecure = false;\n } else if (endpoint.startsWith('http://') || endpoint === DEFAULT_COLLECTOR_URL) {\n insecure = true;\n } else {\n insecure = getSecurityFromEnv();\n }\n\n if (insecure) {\n return grpc.credentials.createInsecure();\n } else {\n return useSecureConnection();\n }\n}\n\nfunction getSecurityFromEnv(): boolean {\n const definedInsecure =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_INSECURE ||\n getEnv().OTEL_EXPORTER_OTLP_INSECURE;\n\n if (definedInsecure) {\n return definedInsecure.toLowerCase() === 'true';\n } else {\n return false;\n }\n}\n\nexport function useSecureConnection(): grpc.ChannelCredentials {\n const rootCertPath = retrieveRootCert();\n const privateKeyPath = retrievePrivateKey();\n const certChainPath = retrieveCertChain();\n\n return grpc.credentials.createSsl(rootCertPath, privateKeyPath, certChainPath);\n}\n\nfunction retrieveRootCert(): Buffer | undefined {\n const rootCertificate =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE ||\n getEnv().OTEL_EXPORTER_OTLP_CERTIFICATE;\n\n if (rootCertificate) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), rootCertificate));\n } catch {\n diag.warn('Failed to read root certificate file');\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction retrievePrivateKey(): Buffer | undefined {\n const clientKey =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY ||\n getEnv().OTEL_EXPORTER_OTLP_CLIENT_KEY;\n\n if (clientKey) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), clientKey));\n } catch {\n diag.warn('Failed to read client certificate private key file');\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction retrieveCertChain(): Buffer | undefined {\n const clientChain =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE ||\n getEnv().OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE;\n\n if (clientChain) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), clientChain));\n } catch {\n diag.warn('Failed to read client certificate chain file');\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction toGrpcCompression(compression: CompressionAlgorithm): GrpcCompressionAlgorithm {\n if (compression === CompressionAlgorithm.NONE)\n return GrpcCompressionAlgorithm.NONE;\n else if (compression === CompressionAlgorithm.GZIP)\n return GrpcCompressionAlgorithm.GZIP;\n return GrpcCompressionAlgorithm.NONE;\n}\n\n/**\n * These values are defined by grpc client\n */\nexport enum GrpcCompressionAlgorithm {\n NONE = 0,\n GZIP = 2\n}\n\nexport function configureCompression(compression: CompressionAlgorithm | undefined): GrpcCompressionAlgorithm {\n if (compression) {\n return toGrpcCompression(compression);\n } else {\n const definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n\n return definedCompression === 'gzip' ? GrpcCompressionAlgorithm.GZIP : GrpcCompressionAlgorithm.NONE;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,sCAAsC;AACtC,kDAAkD;AAClD,4CAA0C;AAC1C,8CAAiE;AACjE,6BAA6B;AAE7B,6BAA0B;AAC1B,yBAAyB;AACzB,mCAIiB;AACjB,0EAI2C;AAE9B,QAAA,qBAAqB,GAAG,uBAAuB,CAAC;AAE7D,SAAgB,MAAM,CACpB,SAA+D,EAC/D,MAAkC;IAElC,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC;IAEzB,MAAM,WAAW,GAA4B,iBAAiB,CAC5D,MAAM,CAAC,WAAW,EAClB,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,CACnC,CAAC;IAEF,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE9D,WAAW;SACR,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAE;QACrC,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,IAAI;QACZ,WAAW;KACZ,CAAC;SACD,IAAI,CAAC,iBAAiB,CAAC,EAAE;QACxB,MAAM,aAAa,GAAQ,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;QAEzE,MAAM,OAAO,GAAG;YACd,oCAAoC,EAA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AI,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,uEAAQ,CAAA;IACR,uEAAQ,CAAA;AACV,CAAC,EAHW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAGnC;AAED,SAAgB,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;SAAM;QACL,MAAM,kBAAkB,GACtB,IAAA,aAAM,GAAE,CAAC,qCAAqC;YAC9C,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QAE1C,OAAO,kBAAkB,KAAK,MAAM;YAClC,CAAC,CAAC,wBAAwB,CAAC,IAAI;YAC/B,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC;KACnC;AACH,CAAC;AAdD,oDAcC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as grpc from '@grpc/grpc-js';\nimport * as protoLoader from '@grpc/proto-loader';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, globalErrorHandler } from '@opentelemetry/core';\nimport * as path from 'path';\nimport { OTLPGRPCExporterNodeBase } from './OTLPGRPCExporterNodeBase';\nimport { URL } from 'url';\nimport * as fs from 'fs';\nimport {\n GRPCQueueItem,\n OTLPGRPCExporterConfigNode,\n ServiceClientType,\n} from './types';\nimport {\n CompressionAlgorithm,\n ExportServiceError,\n OTLPExporterError,\n} from '@opentelemetry/otlp-exporter-base';\n\nexport const DEFAULT_COLLECTOR_URL = 'http://localhost:4317';\n\nexport function onInit<ExportItem, ServiceRequest>(\n collector: OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest>,\n config: OTLPGRPCExporterConfigNode\n): void {\n collector.grpcQueue = [];\n\n const credentials: grpc.ChannelCredentials = configureSecurity(\n config.credentials,\n collector.getUrlFromConfig(config)\n );\n\n const includeDirs = [path.resolve(__dirname, '..', 'protos')];\n\n protoLoader\n .load(collector.getServiceProtoPath(), {\n keepCase: false,\n longs: String,\n enums: String,\n defaults: true,\n oneofs: true,\n includeDirs,\n })\n .then(packageDefinition => {\n const packageObject: any = grpc.loadPackageDefinition(packageDefinition);\n\n const options = {\n 'grpc.default_compression_algorithm': collector.compression,\n };\n\n if (collector.getServiceClientType() === ServiceClientType.SPANS) {\n collector.serviceClient =\n new packageObject.opentelemetry.proto.collector.trace.v1.TraceService(\n collector.url,\n credentials,\n options\n );\n } else {\n collector.serviceClient =\n new packageObject.opentelemetry.proto.collector.metrics.v1.MetricsService(\n collector.url,\n credentials,\n options\n );\n }\n\n if (collector.grpcQueue.length > 0) {\n const queue = collector.grpcQueue.splice(0);\n queue.forEach((item: GRPCQueueItem<ExportItem>) => {\n collector.send(item.objects, item.onSuccess, item.onError);\n });\n }\n })\n .catch(err => {\n globalErrorHandler(err);\n });\n}\n\nexport function send<ExportItem, ServiceRequest>(\n collector: OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest>,\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n if (collector.serviceClient) {\n const serviceRequest = collector.convert(objects);\n const deadline = Date.now() + collector.timeoutMillis;\n\n collector.serviceClient.export(\n serviceRequest,\n collector.metadata || new grpc.Metadata(),\n { deadline: deadline },\n (err: ExportServiceError) => {\n if (err) {\n diag.error('Service request', serviceRequest);\n onError(err);\n } else {\n diag.debug('Objects sent');\n onSuccess();\n }\n }\n );\n } else {\n collector.grpcQueue.push({\n objects,\n onSuccess,\n onError,\n });\n }\n}\n\nexport function validateAndNormalizeUrl(url: string): string {\n const hasProtocol = url.match(/^([\\w]{1,8}):\\/\\//);\n if (!hasProtocol) {\n url = `https://${url}`;\n }\n const target = new URL(url);\n if (target.pathname && target.pathname !== '/') {\n diag.warn(\n 'URL path should not be set when using grpc, the path part of the URL will be ignored.'\n );\n }\n if (target.protocol !== '' && !target.protocol?.match(/^(http)s?:$/)) {\n diag.warn('URL protocol should be http(s)://. Using http://.');\n }\n return target.host;\n}\n\nexport function configureSecurity(\n credentials: grpc.ChannelCredentials | undefined,\n endpoint: string\n): grpc.ChannelCredentials {\n let insecure: boolean;\n\n if (credentials) {\n return credentials;\n } else if (endpoint.startsWith('https://')) {\n insecure = false;\n } else if (\n endpoint.startsWith('http://') ||\n endpoint === DEFAULT_COLLECTOR_URL\n ) {\n insecure = true;\n } else {\n insecure = getSecurityFromEnv();\n }\n\n if (insecure) {\n return grpc.credentials.createInsecure();\n } else {\n return useSecureConnection();\n }\n}\n\nfunction getSecurityFromEnv(): boolean {\n const definedInsecure =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_INSECURE ||\n getEnv().OTEL_EXPORTER_OTLP_INSECURE;\n\n if (definedInsecure) {\n return definedInsecure.toLowerCase() === 'true';\n } else {\n return false;\n }\n}\n\nexport function useSecureConnection(): grpc.ChannelCredentials {\n const rootCertPath = retrieveRootCert();\n const privateKeyPath = retrievePrivateKey();\n const certChainPath = retrieveCertChain();\n\n return grpc.credentials.createSsl(\n rootCertPath,\n privateKeyPath,\n certChainPath\n );\n}\n\nfunction retrieveRootCert(): Buffer | undefined {\n const rootCertificate =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE ||\n getEnv().OTEL_EXPORTER_OTLP_CERTIFICATE;\n\n if (rootCertificate) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), rootCertificate));\n } catch {\n diag.warn('Failed to read root certificate file');\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction retrievePrivateKey(): Buffer | undefined {\n const clientKey =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY ||\n getEnv().OTEL_EXPORTER_OTLP_CLIENT_KEY;\n\n if (clientKey) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), clientKey));\n } catch {\n diag.warn('Failed to read client certificate private key file');\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction retrieveCertChain(): Buffer | undefined {\n const clientChain =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE ||\n getEnv().OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE;\n\n if (clientChain) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), clientChain));\n } catch {\n diag.warn('Failed to read client certificate chain file');\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction toGrpcCompression(\n compression: CompressionAlgorithm\n): GrpcCompressionAlgorithm {\n if (compression === CompressionAlgorithm.NONE)\n return GrpcCompressionAlgorithm.NONE;\n else if (compression === CompressionAlgorithm.GZIP)\n return GrpcCompressionAlgorithm.GZIP;\n return GrpcCompressionAlgorithm.NONE;\n}\n\n/**\n * These values are defined by grpc client\n */\nexport enum GrpcCompressionAlgorithm {\n NONE = 0,\n GZIP = 2,\n}\n\nexport function configureCompression(\n compression: CompressionAlgorithm | undefined\n): GrpcCompressionAlgorithm {\n if (compression) {\n return toGrpcCompression(compression);\n } else {\n const definedCompression =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||\n getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n\n return definedCompression === 'gzip'\n ? GrpcCompressionAlgorithm.GZIP\n : GrpcCompressionAlgorithm.NONE;\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.35.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.35.0';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/otlp-grpc-exporter-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "OpenTelemetry OTLP-gRPC Exporter base (for internal use only)",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"types": "build/src/index.d.ts",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@babel/core": "7.16.0",
|
|
53
53
|
"@opentelemetry/api": "^1.0.0",
|
|
54
|
-
"@opentelemetry/otlp-transformer": "0.
|
|
55
|
-
"@opentelemetry/resources": "1.
|
|
56
|
-
"@opentelemetry/sdk-trace-base": "1.
|
|
54
|
+
"@opentelemetry/otlp-transformer": "0.35.0",
|
|
55
|
+
"@opentelemetry/resources": "1.9.0",
|
|
56
|
+
"@opentelemetry/sdk-trace-base": "1.9.0",
|
|
57
57
|
"@types/mocha": "10.0.0",
|
|
58
58
|
"@types/node": "18.6.5",
|
|
59
59
|
"@types/sinon": "10.0.13",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"mocha": "10.0.0",
|
|
63
63
|
"nyc": "15.1.0",
|
|
64
64
|
"rimraf": "3.0.2",
|
|
65
|
-
"sinon": "
|
|
65
|
+
"sinon": "15.0.0",
|
|
66
66
|
"ts-loader": "8.4.0",
|
|
67
67
|
"ts-mocha": "10.0.0",
|
|
68
68
|
"typescript": "4.4.4"
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@grpc/grpc-js": "^1.7.1",
|
|
75
75
|
"@grpc/proto-loader": "^0.7.3",
|
|
76
|
-
"@opentelemetry/core": "1.
|
|
77
|
-
"@opentelemetry/otlp-exporter-base": "0.
|
|
76
|
+
"@opentelemetry/core": "1.9.0",
|
|
77
|
+
"@opentelemetry/otlp-exporter-base": "0.35.0"
|
|
78
78
|
},
|
|
79
79
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-grpc-exporter-base",
|
|
80
80
|
"sideEffects": false,
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "08f597f3a3d71a4852b0afbba120af15ca038121"
|
|
82
82
|
}
|