Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/otlp-grpc-exporter-base

Package Overview
Dependencies
Maintainers
3
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/otlp-grpc-exporter-base - npm Package Compare versions

Comparing version 0.49.1 to 0.50.0

build/src/create-service-client-constructor.d.ts

7

build/src/index.d.ts

@@ -1,4 +0,5 @@

export * from './OTLPGRPCExporterNodeBase';
export { ServiceClientType, OTLPGRPCExporterConfigNode } from './types';
export { DEFAULT_COLLECTOR_URL, validateAndNormalizeUrl, GrpcCompressionAlgorithm, } from './util';
export { OTLPGRPCExporterNodeBase } from './OTLPGRPCExporterNodeBase';
export { OTLPGRPCExporterConfigNode } from './types';
export { DEFAULT_COLLECTOR_URL, validateAndNormalizeUrl } from './util';
export { MetricsSerializer, TraceSerializer, LogsSerializer, ISerializer, } from './serializers';
//# sourceMappingURL=index.d.ts.map

@@ -17,21 +17,13 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrpcCompressionAlgorithm = exports.validateAndNormalizeUrl = exports.DEFAULT_COLLECTOR_URL = exports.ServiceClientType = void 0;
__exportStar(require("./OTLPGRPCExporterNodeBase"), exports);
var types_1 = require("./types");
Object.defineProperty(exports, "ServiceClientType", { enumerable: true, get: function () { return types_1.ServiceClientType; } });
exports.LogsSerializer = exports.TraceSerializer = exports.MetricsSerializer = exports.validateAndNormalizeUrl = exports.DEFAULT_COLLECTOR_URL = exports.OTLPGRPCExporterNodeBase = void 0;
var OTLPGRPCExporterNodeBase_1 = require("./OTLPGRPCExporterNodeBase");
Object.defineProperty(exports, "OTLPGRPCExporterNodeBase", { enumerable: true, get: function () { return OTLPGRPCExporterNodeBase_1.OTLPGRPCExporterNodeBase; } });
var util_1 = require("./util");
Object.defineProperty(exports, "DEFAULT_COLLECTOR_URL", { enumerable: true, get: function () { return util_1.DEFAULT_COLLECTOR_URL; } });
Object.defineProperty(exports, "validateAndNormalizeUrl", { enumerable: true, get: function () { return util_1.validateAndNormalizeUrl; } });
Object.defineProperty(exports, "GrpcCompressionAlgorithm", { enumerable: true, get: function () { return util_1.GrpcCompressionAlgorithm; } });
var serializers_1 = require("./serializers");
Object.defineProperty(exports, "MetricsSerializer", { enumerable: true, get: function () { return serializers_1.MetricsSerializer; } });
Object.defineProperty(exports, "TraceSerializer", { enumerable: true, get: function () { return serializers_1.TraceSerializer; } });
Object.defineProperty(exports, "LogsSerializer", { enumerable: true, get: function () { return serializers_1.LogsSerializer; } });
//# sourceMappingURL=index.js.map

@@ -1,24 +0,18 @@

import { Metadata } from '@grpc/grpc-js';
import { OTLPGRPCExporterConfigNode, GRPCQueueItem, ServiceClientType } from './types';
import { ServiceClient } from './types';
import { GrpcCompressionAlgorithm } from './util';
import { OTLPExporterBase, OTLPExporterError } from '@opentelemetry/otlp-exporter-base';
import { GRPCQueueItem, OTLPGRPCExporterConfigNode } from './types';
import { CompressionAlgorithm, OTLPExporterBase, OTLPExporterError } from '@opentelemetry/otlp-exporter-base';
import { ISerializer } from './serializers';
/**
* OTLP Exporter abstract base class
*/
export declare abstract class OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest> extends OTLPExporterBase<OTLPGRPCExporterConfigNode, ExportItem, ServiceRequest> {
export declare abstract class OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest, ServiceResponse> extends OTLPExporterBase<OTLPGRPCExporterConfigNode, ExportItem, ServiceRequest> {
grpcQueue: GRPCQueueItem<ExportItem>[];
metadata?: Metadata;
serviceClient?: ServiceClient;
private _send;
compression: GrpcCompressionAlgorithm;
constructor(config?: OTLPGRPCExporterConfigNode);
private _sendPromise;
onInit(config: OTLPGRPCExporterConfigNode): void;
compression: CompressionAlgorithm;
private _transport;
private _serializer;
constructor(config: OTLPGRPCExporterConfigNode | undefined, signalSpecificMetadata: Record<string, string>, grpcName: string, grpcPath: string, serializer: ISerializer<ServiceRequest, ServiceResponse>);
onInit(): void;
onShutdown(): void;
send(objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
onShutdown(): void;
abstract getServiceProtoPath(): string;
abstract getServiceClientType(): ServiceClientType;
abstract getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string;
}
//# sourceMappingURL=OTLPGRPCExporterNodeBase.d.ts.map

@@ -20,6 +20,6 @@ "use strict";

const api_1 = require("@opentelemetry/api");
const grpc_js_1 = require("@grpc/grpc-js");
const core_1 = require("@opentelemetry/core");
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const grpc_exporter_transport_1 = require("./grpc-exporter-transport");
const util_1 = require("./util");
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
/**

@@ -29,35 +29,50 @@ * OTLP Exporter abstract base class

class OTLPGRPCExporterNodeBase extends otlp_exporter_base_1.OTLPExporterBase {
constructor(config = {}) {
constructor(config = {}, signalSpecificMetadata, grpcName, grpcPath, serializer) {
var _a;
super(config);
this.grpcQueue = [];
this.serviceClient = undefined;
this._serializer = serializer;
if (config.headers) {
api_1.diag.warn('Headers cannot be set when using grpc');
}
const headers = core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS);
this.metadata = config.metadata || new grpc_js_1.Metadata();
for (const [k, v] of Object.entries(headers)) {
this.metadata.set(k, v);
const nonSignalSpecificMetadata = core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS);
const rawMetadata = Object.assign({}, nonSignalSpecificMetadata, signalSpecificMetadata);
let credentialProvider = () => {
return (0, util_1.configureCredentials)(undefined, this.getUrlFromConfig(config));
};
if (config.credentials != null) {
const credentials = config.credentials;
credentialProvider = () => {
return credentials;
};
}
// Ensure we don't modify the original.
const configMetadata = (_a = config.metadata) === null || _a === void 0 ? void 0 : _a.clone();
const metadataProvider = () => {
const metadata = configMetadata !== null && configMetadata !== void 0 ? configMetadata : (0, grpc_exporter_transport_1.createEmptyMetadata)();
for (const [key, value] of Object.entries(rawMetadata)) {
// only override with env var data if the key has no values.
// not using Metadata.merge() as it will keep both values.
if (metadata.get(key).length < 1) {
metadata.set(key, value);
}
}
return metadata;
};
this.compression = (0, util_1.configureCompression)(config.compression);
this._transport = new grpc_exporter_transport_1.GrpcExporterTransport({
address: this.getDefaultUrl(config),
compression: this.compression,
credentials: credentialProvider,
grpcName: grpcName,
grpcPath: grpcPath,
metadata: metadataProvider,
timeoutMillis: this.timeoutMillis,
});
}
_sendPromise(objects, onSuccess, onError) {
const promise = new Promise((resolve, reject) => {
this._send(this, objects, resolve, reject);
}).then(onSuccess, onError);
this._sendingPromises.push(promise);
const popPromise = () => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
};
promise.then(popPromise, popPromise);
onInit() {
// Intentionally left empty; nothing to do.
}
onInit(config) {
// defer to next tick and lazy load to avoid loading grpc too early
// and making this impossible to be instrumented
setImmediate(() => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { onInit } = require('./util');
onInit(this, config);
});
onShutdown() {
this._transport.shutdown();
}

@@ -69,23 +84,27 @@ send(objects, onSuccess, onError) {

}
if (!this._send) {
// defer to next tick and lazy load to avoid loading grpc too early
// and making this impossible to be instrumented
setImmediate(() => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { send } = require('./util');
this._send = send;
this._sendPromise(objects, onSuccess, onError);
});
const converted = this.convert(objects);
const data = this._serializer.serializeRequest(converted);
if (data == null) {
onError(new Error('Could not serialize message'));
return;
}
else {
this._sendPromise(objects, onSuccess, onError);
}
const promise = this._transport.send(data).then(response => {
if (response.status === 'success') {
onSuccess();
return;
}
if (response.status === 'failure' && response.error) {
onError(response.error);
}
onError(new otlp_exporter_base_1.OTLPExporterError('Export failed with unknown error'));
}, onError);
this._sendingPromises.push(promise);
const popPromise = () => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
};
promise.then(popPromise, popPromise);
}
onShutdown() {
if (this.serviceClient) {
this.serviceClient.close();
}
}
}
exports.OTLPGRPCExporterNodeBase = OTLPGRPCExporterNodeBase;
//# sourceMappingURL=OTLPGRPCExporterNodeBase.js.map

@@ -1,2 +0,2 @@

import * as grpc from '@grpc/grpc-js';
import type { ChannelCredentials, Metadata } from '@grpc/grpc-js';
import { CompressionAlgorithm, OTLPExporterConfigBase, OTLPExporterError } from '@opentelemetry/otlp-exporter-base';

@@ -13,21 +13,9 @@ /**

/**
* Service Client for sending spans/metrics/logs
*/
export interface ServiceClient {
export: (request: any, metadata: grpc.Metadata, options: grpc.CallOptions, callback: Function) => {};
close(): void;
}
/**
* OTLP Exporter Config for Node
*/
export interface OTLPGRPCExporterConfigNode extends OTLPExporterConfigBase {
credentials?: grpc.ChannelCredentials;
metadata?: grpc.Metadata;
credentials?: ChannelCredentials;
metadata?: Metadata;
compression?: CompressionAlgorithm;
}
export declare enum ServiceClientType {
SPANS = 0,
METRICS = 1,
LOGS = 2
}
//# sourceMappingURL=types.d.ts.map

@@ -18,9 +18,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceClientType = void 0;
var ServiceClientType;
(function (ServiceClientType) {
ServiceClientType[ServiceClientType["SPANS"] = 0] = "SPANS";
ServiceClientType[ServiceClientType["METRICS"] = 1] = "METRICS";
ServiceClientType[ServiceClientType["LOGS"] = 2] = "LOGS";
})(ServiceClientType = exports.ServiceClientType || (exports.ServiceClientType = {}));
//# sourceMappingURL=types.js.map

@@ -1,19 +0,11 @@

import * as grpc from '@grpc/grpc-js';
import { OTLPGRPCExporterNodeBase } from './OTLPGRPCExporterNodeBase';
import { OTLPGRPCExporterConfigNode } from './types';
import { OTLPExporterError, CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';
import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';
import type { ChannelCredentials } from '@grpc/grpc-js';
export declare const DEFAULT_COLLECTOR_URL = "http://localhost:4317";
export declare function onInit<ExportItem, ServiceRequest>(collector: OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest>, config: OTLPGRPCExporterConfigNode): void;
export declare function send<ExportItem, ServiceRequest>(collector: OTLPGRPCExporterNodeBase<ExportItem, ServiceRequest>, objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
export declare function validateAndNormalizeUrl(url: string): string;
export declare function configureSecurity(credentials: grpc.ChannelCredentials | undefined, endpoint: string): grpc.ChannelCredentials;
export declare function useSecureConnection(): grpc.ChannelCredentials;
export declare function configureCredentials(credentials: ChannelCredentials | undefined, endpoint: string): ChannelCredentials;
/**
* These values are defined by grpc client
* Exported for testing
*/
export declare enum GrpcCompressionAlgorithm {
NONE = 0,
GZIP = 2
}
export declare function configureCompression(compression: CompressionAlgorithm | undefined): GrpcCompressionAlgorithm;
export declare function getCredentialsFromEnvironment(): ChannelCredentials;
export declare function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm;
//# sourceMappingURL=util.d.ts.map

@@ -18,4 +18,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.configureCompression = exports.GrpcCompressionAlgorithm = exports.useSecureConnection = exports.configureSecurity = exports.validateAndNormalizeUrl = exports.send = exports.onInit = exports.DEFAULT_COLLECTOR_URL = void 0;
const grpc = require("@grpc/grpc-js");
exports.configureCompression = exports.getCredentialsFromEnvironment = exports.configureCredentials = exports.validateAndNormalizeUrl = exports.DEFAULT_COLLECTOR_URL = void 0;
const api_1 = require("@opentelemetry/api");

@@ -26,72 +25,5 @@ const core_1 = require("@opentelemetry/core");

const fs = require("fs");
const types_1 = require("./types");
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const MetricsExportServiceClient_1 = require("./MetricsExportServiceClient");
const TraceExportServiceClient_1 = require("./TraceExportServiceClient");
const LogsExportServiceClient_1 = require("./LogsExportServiceClient");
const grpc_exporter_transport_1 = require("./grpc-exporter-transport");
exports.DEFAULT_COLLECTOR_URL = 'http://localhost:4317';
function onInit(collector, config) {
collector.grpcQueue = [];
const credentials = configureSecurity(config.credentials, collector.getUrlFromConfig(config));
try {
if (collector.getServiceClientType() === types_1.ServiceClientType.SPANS) {
const client = new TraceExportServiceClient_1.TraceExportServiceClient(collector.url, credentials, {
'grpc.default_compression_algorithm': collector.compression.valueOf(),
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
collector.serviceClient = client;
}
else if (collector.getServiceClientType() === types_1.ServiceClientType.METRICS) {
const client = new MetricsExportServiceClient_1.MetricExportServiceClient(collector.url, credentials, {
'grpc.default_compression_algorithm': collector.compression.valueOf(),
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
collector.serviceClient = client;
}
else if (collector.getServiceClientType() === types_1.ServiceClientType.LOGS) {
const client = new LogsExportServiceClient_1.LogsExportServiceClient(collector.url, credentials, {
'grpc.default_compression_algorithm': collector.compression.valueOf(),
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
collector.serviceClient = client;
}
}
catch (err) {
(0, core_1.globalErrorHandler)(err);
}
if (collector.grpcQueue.length > 0) {
const queue = collector.grpcQueue.splice(0);
queue.forEach((item) => {
collector.send(item.objects, item.onSuccess, item.onError);
});
}
}
exports.onInit = onInit;
function send(collector, objects, onSuccess, onError) {
if (collector.serviceClient) {
const serviceRequest = collector.convert(objects);
const deadline = Date.now() + collector.timeoutMillis;
collector.serviceClient.export(serviceRequest, collector.metadata || new grpc.Metadata(), { deadline: deadline }, (err) => {
if (err) {
api_1.diag.error('Service request', serviceRequest);
onError(err);
}
else {
api_1.diag.debug('Objects sent');
onSuccess();
}
});
}
else {
collector.grpcQueue.push({
objects,
onSuccess,
onError,
});
}
}
exports.send = send;
function validateAndNormalizeUrl(url) {

@@ -116,3 +48,3 @@ var _a;

exports.validateAndNormalizeUrl = validateAndNormalizeUrl;
function configureSecurity(credentials, endpoint) {
function configureCredentials(credentials, endpoint) {
let insecure;

@@ -133,9 +65,9 @@ if (credentials) {

if (insecure) {
return grpc.credentials.createInsecure();
return (0, grpc_exporter_transport_1.createInsecureCredentials)();
}
else {
return useSecureConnection();
return getCredentialsFromEnvironment();
}
}
exports.configureSecurity = configureSecurity;
exports.configureCredentials = configureCredentials;
function getSecurityFromEnv() {

@@ -151,9 +83,12 @@ const definedInsecure = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_INSECURE ||

}
function useSecureConnection() {
const rootCertPath = retrieveRootCert();
const privateKeyPath = retrievePrivateKey();
const certChainPath = retrieveCertChain();
return grpc.credentials.createSsl(rootCertPath, privateKeyPath, certChainPath);
/**
* Exported for testing
*/
function getCredentialsFromEnvironment() {
const rootCert = retrieveRootCert();
const privateKey = retrievePrivateKey();
const certChain = retrieveCertChain();
return (0, grpc_exporter_transport_1.createSslCredentials)(rootCert, privateKey, certChain);
}
exports.useSecureConnection = useSecureConnection;
exports.getCredentialsFromEnvironment = getCredentialsFromEnvironment;
function retrieveRootCert() {

@@ -207,30 +142,18 @@ const rootCertificate = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE ||

}
function toGrpcCompression(compression) {
if (compression === otlp_exporter_base_1.CompressionAlgorithm.NONE)
return GrpcCompressionAlgorithm.NONE;
else if (compression === otlp_exporter_base_1.CompressionAlgorithm.GZIP)
return GrpcCompressionAlgorithm.GZIP;
return GrpcCompressionAlgorithm.NONE;
}
/**
* These values are defined by grpc client
*/
var GrpcCompressionAlgorithm;
(function (GrpcCompressionAlgorithm) {
GrpcCompressionAlgorithm[GrpcCompressionAlgorithm["NONE"] = 0] = "NONE";
GrpcCompressionAlgorithm[GrpcCompressionAlgorithm["GZIP"] = 2] = "GZIP";
})(GrpcCompressionAlgorithm = exports.GrpcCompressionAlgorithm || (exports.GrpcCompressionAlgorithm = {}));
function configureCompression(compression) {
if (compression) {
return toGrpcCompression(compression);
if (compression != null) {
return compression;
}
else {
const definedCompression = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||
(0, core_1.getEnv)().OTEL_EXPORTER_OTLP_COMPRESSION;
return definedCompression === 'gzip'
? GrpcCompressionAlgorithm.GZIP
: GrpcCompressionAlgorithm.NONE;
const envCompression = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||
(0, core_1.getEnv)().OTEL_EXPORTER_OTLP_COMPRESSION;
if (envCompression === 'gzip') {
return otlp_exporter_base_1.CompressionAlgorithm.GZIP;
}
else if (envCompression === 'none') {
return otlp_exporter_base_1.CompressionAlgorithm.NONE;
}
api_1.diag.warn('Unknown compression "' + envCompression + '", falling back to "none"');
return otlp_exporter_base_1.CompressionAlgorithm.NONE;
}
exports.configureCompression = configureCompression;
//# sourceMappingURL=util.js.map

@@ -1,2 +0,2 @@

export declare const VERSION = "0.49.1";
export declare const VERSION = "0.50.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.49.1';
exports.VERSION = '0.50.0';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/otlp-grpc-exporter-base",
"version": "0.49.1",
"version": "0.50.0",
"description": "OpenTelemetry OTLP-gRPC Exporter base (for internal use only)",

@@ -52,5 +52,5 @@ "main": "build/src/index.js",

"@opentelemetry/api": "1.8.0",
"@opentelemetry/otlp-transformer": "0.49.1",
"@opentelemetry/resources": "1.22.0",
"@opentelemetry/sdk-trace-base": "1.22.0",
"@opentelemetry/otlp-transformer": "0.50.0",
"@opentelemetry/resources": "1.23.0",
"@opentelemetry/sdk-trace-base": "1.23.0",
"@types/mocha": "10.0.6",

@@ -76,4 +76,4 @@ "@types/node": "18.6.5",

"@grpc/grpc-js": "^1.7.1",
"@opentelemetry/core": "1.22.0",
"@opentelemetry/otlp-exporter-base": "0.49.1",
"@opentelemetry/core": "1.23.0",
"@opentelemetry/otlp-exporter-base": "0.50.0",
"protobufjs": "^7.2.3"

@@ -83,3 +83,3 @@ },

"sideEffects": false,
"gitHead": "3920b158d08daa776280bde68a79e44bafa4e8ea"
"gitHead": "5231aa255047fbc6ee3d6a299f4423ab2f8a5fbc"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc