Update test framework: fix run_tests.py to support all test files, add auto-import-check for test files

This commit is contained in:
qiaoxinjiu
2026-05-09 15:11:30 +08:00
parent eb053a347f
commit eaba8328da
21739 changed files with 2236758 additions and 719 deletions

View File

@@ -0,0 +1,9 @@
import { OTLPGRPCExporterConfigNode } from '../types';
import { OtlpGrpcConfiguration } from './otlp-grpc-configuration';
/**
* @deprecated
* @param config
* @param signalIdentifier
*/
export declare function convertLegacyOtlpGrpcOptions(config: OTLPGRPCExporterConfigNode, signalIdentifier: string): OtlpGrpcConfiguration;
//# sourceMappingURL=convert-legacy-otlp-grpc-options.d.ts.map

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertLegacyOtlpGrpcOptions = void 0;
const api_1 = require("@opentelemetry/api");
const otlp_grpc_configuration_1 = require("./otlp-grpc-configuration");
const grpc_exporter_transport_1 = require("../grpc-exporter-transport");
const otlp_grpc_env_configuration_1 = require("./otlp-grpc-env-configuration");
/**
* @deprecated
* @param config
* @param signalIdentifier
*/
function convertLegacyOtlpGrpcOptions(config, signalIdentifier) {
if (config.headers) {
api_1.diag.warn('Headers cannot be set when using grpc');
}
// keep credentials locally in case user updates the reference on the config object
const userProvidedCredentials = config.credentials;
return (0, otlp_grpc_configuration_1.mergeOtlpGrpcConfigurationWithDefaults)({
url: config.url,
metadata: () => {
// metadata resolution strategy is merge, so we can return empty here, and it will not override the rest of the settings.
return config.metadata ?? (0, grpc_exporter_transport_1.createEmptyMetadata)();
},
compression: config.compression,
timeoutMillis: config.timeoutMillis,
concurrencyLimit: config.concurrencyLimit,
credentials: userProvidedCredentials != null
? () => userProvidedCredentials
: undefined,
}, (0, otlp_grpc_env_configuration_1.getOtlpGrpcConfigurationFromEnv)(signalIdentifier), (0, otlp_grpc_configuration_1.getOtlpGrpcDefaultConfiguration)());
}
exports.convertLegacyOtlpGrpcOptions = convertLegacyOtlpGrpcOptions;
//# sourceMappingURL=convert-legacy-otlp-grpc-options.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"convert-legacy-otlp-grpc-options.js","sourceRoot":"","sources":["../../../src/configuration/convert-legacy-otlp-grpc-options.ts"],"names":[],"mappings":";;;AAgBA,4CAA0C;AAC1C,uEAImC;AACnC,wEAAiE;AACjE,+EAAgF;AAEhF;;;;GAIG;AACH,SAAgB,4BAA4B,CAC1C,MAAkC,EAClC,gBAAwB;IAExB,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,UAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;KACpD;IAED,mFAAmF;IACnF,MAAM,uBAAuB,GAAG,MAAM,CAAC,WAAW,CAAC;IACnD,OAAO,IAAA,gEAAsC,EAC3C;QACE,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,QAAQ,EAAE,GAAG,EAAE;YACb,yHAAyH;YACzH,OAAO,MAAM,CAAC,QAAQ,IAAI,IAAA,6CAAmB,GAAE,CAAC;QAClD,CAAC;QACD,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,WAAW,EACT,uBAAuB,IAAI,IAAI;YAC7B,CAAC,CAAC,GAAG,EAAE,CAAC,uBAAuB;YAC/B,CAAC,CAAC,SAAS;KAChB,EACD,IAAA,6DAA+B,EAAC,gBAAgB,CAAC,EACjD,IAAA,yDAA+B,GAAE,CAClC,CAAC;AACJ,CAAC;AA5BD,oEA4BC","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 */\nimport { OTLPGRPCExporterConfigNode } from '../types';\nimport { diag } from '@opentelemetry/api';\nimport {\n getOtlpGrpcDefaultConfiguration,\n mergeOtlpGrpcConfigurationWithDefaults,\n OtlpGrpcConfiguration,\n} from './otlp-grpc-configuration';\nimport { createEmptyMetadata } from '../grpc-exporter-transport';\nimport { getOtlpGrpcConfigurationFromEnv } from './otlp-grpc-env-configuration';\n\n/**\n * @deprecated\n * @param config\n * @param signalIdentifier\n */\nexport function convertLegacyOtlpGrpcOptions(\n config: OTLPGRPCExporterConfigNode,\n signalIdentifier: string\n): OtlpGrpcConfiguration {\n if (config.headers) {\n diag.warn('Headers cannot be set when using grpc');\n }\n\n // keep credentials locally in case user updates the reference on the config object\n const userProvidedCredentials = config.credentials;\n return mergeOtlpGrpcConfigurationWithDefaults(\n {\n url: config.url,\n metadata: () => {\n // metadata resolution strategy is merge, so we can return empty here, and it will not override the rest of the settings.\n return config.metadata ?? createEmptyMetadata();\n },\n compression: config.compression,\n timeoutMillis: config.timeoutMillis,\n concurrencyLimit: config.concurrencyLimit,\n credentials:\n userProvidedCredentials != null\n ? () => userProvidedCredentials\n : undefined,\n },\n getOtlpGrpcConfigurationFromEnv(signalIdentifier),\n getOtlpGrpcDefaultConfiguration()\n );\n}\n"]}

View File

@@ -0,0 +1,22 @@
import { OtlpSharedConfiguration } from '@opentelemetry/otlp-exporter-base';
import type { ChannelCredentials, Metadata } from '@grpc/grpc-js';
export interface OtlpGrpcConfiguration extends OtlpSharedConfiguration {
url: string;
metadata: () => Metadata;
credentials: () => ChannelCredentials;
}
/**
* Unresolved configuration where parts of the config may depend on other config options being resolved first.
*/
export interface UnresolvedOtlpGrpcConfiguration extends OtlpSharedConfiguration {
url: string;
metadata: () => Metadata;
/**
* Credentials are based on the final resolved URL
*/
credentials: (url: string) => () => ChannelCredentials;
}
export declare function validateAndNormalizeUrl(url: string): string;
export declare function mergeOtlpGrpcConfigurationWithDefaults(userProvidedConfiguration: Partial<OtlpGrpcConfiguration>, fallbackConfiguration: Partial<UnresolvedOtlpGrpcConfiguration>, defaultConfiguration: UnresolvedOtlpGrpcConfiguration): OtlpGrpcConfiguration;
export declare function getOtlpGrpcDefaultConfiguration(): UnresolvedOtlpGrpcConfiguration;
//# sourceMappingURL=otlp-grpc-configuration.d.ts.map

View File

@@ -0,0 +1,93 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOtlpGrpcDefaultConfiguration = exports.mergeOtlpGrpcConfigurationWithDefaults = exports.validateAndNormalizeUrl = void 0;
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const grpc_exporter_transport_1 = require("../grpc-exporter-transport");
const version_1 = require("../version");
const url_1 = require("url");
const api_1 = require("@opentelemetry/api");
function validateAndNormalizeUrl(url) {
url = url.trim();
const hasProtocol = url.match(/^([\w]{1,8}):\/\//);
if (!hasProtocol) {
url = `https://${url}`;
}
const target = new url_1.URL(url);
if (target.protocol === 'unix:') {
return url;
}
if (target.pathname && target.pathname !== '/') {
api_1.diag.warn('URL path should not be set when using grpc, the path part of the URL will be ignored.');
}
if (target.protocol !== '' && !target.protocol?.match(/^(http)s?:$/)) {
api_1.diag.warn('URL protocol should be http(s)://. Using http://.');
}
return target.host;
}
exports.validateAndNormalizeUrl = validateAndNormalizeUrl;
function overrideMetadataEntriesIfNotPresent(metadata, additionalMetadata) {
for (const [key, value] of Object.entries(additionalMetadata.getMap())) {
// 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);
}
}
}
function mergeOtlpGrpcConfigurationWithDefaults(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration) {
const rawUrl = userProvidedConfiguration.url ??
fallbackConfiguration.url ??
defaultConfiguration.url;
return {
...(0, otlp_exporter_base_1.mergeOtlpSharedConfigurationWithDefaults)(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration),
metadata: () => {
const metadata = defaultConfiguration.metadata();
overrideMetadataEntriesIfNotPresent(metadata,
// clone to ensure we don't modify what the user gave us in case they hold on to the returned reference
userProvidedConfiguration.metadata?.().clone() ?? (0, grpc_exporter_transport_1.createEmptyMetadata)());
overrideMetadataEntriesIfNotPresent(metadata, fallbackConfiguration.metadata?.() ?? (0, grpc_exporter_transport_1.createEmptyMetadata)());
return metadata;
},
url: validateAndNormalizeUrl(rawUrl),
credentials: userProvidedConfiguration.credentials ??
fallbackConfiguration.credentials?.(rawUrl) ??
defaultConfiguration.credentials(rawUrl),
};
}
exports.mergeOtlpGrpcConfigurationWithDefaults = mergeOtlpGrpcConfigurationWithDefaults;
function getOtlpGrpcDefaultConfiguration() {
return {
...(0, otlp_exporter_base_1.getSharedConfigurationDefaults)(),
metadata: () => {
const metadata = (0, grpc_exporter_transport_1.createEmptyMetadata)();
metadata.set('User-Agent', `OTel-OTLP-Exporter-JavaScript/${version_1.VERSION}`);
return metadata;
},
url: 'http://localhost:4317',
credentials: (url) => {
if (url.startsWith('http://')) {
return () => (0, grpc_exporter_transport_1.createInsecureCredentials)();
}
else {
return () => (0, grpc_exporter_transport_1.createSslCredentials)();
}
},
};
}
exports.getOtlpGrpcDefaultConfiguration = getOtlpGrpcDefaultConfiguration;
//# sourceMappingURL=otlp-grpc-configuration.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
import { UnresolvedOtlpGrpcConfiguration } from './otlp-grpc-configuration';
export declare function getOtlpGrpcConfigurationFromEnv(signalIdentifier: string): Partial<UnresolvedOtlpGrpcConfiguration>;
//# sourceMappingURL=otlp-grpc-env-configuration.d.ts.map

View File

@@ -0,0 +1,159 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOtlpGrpcConfigurationFromEnv = void 0;
const core_1 = require("@opentelemetry/core");
const grpc_exporter_transport_1 = require("../grpc-exporter-transport");
const node_http_1 = require("@opentelemetry/otlp-exporter-base/node-http");
const fs = require("fs");
const path = require("path");
const api_1 = require("@opentelemetry/api");
function fallbackIfNullishOrBlank(signalSpecific, nonSignalSpecific) {
if (signalSpecific != null && signalSpecific !== '') {
return signalSpecific;
}
if (nonSignalSpecific != null && nonSignalSpecific !== '') {
return nonSignalSpecific;
}
return undefined;
}
function getMetadataFromEnv(signalIdentifier) {
const signalSpecificRawHeaders = process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`]?.trim();
const nonSignalSpecificRawHeaders = process.env['OTEL_EXPORTER_OTLP_HEADERS']?.trim();
const signalSpecificHeaders = (0, core_1.parseKeyPairsIntoRecord)(signalSpecificRawHeaders);
const nonSignalSpecificHeaders = (0, core_1.parseKeyPairsIntoRecord)(nonSignalSpecificRawHeaders);
if (Object.keys(signalSpecificHeaders).length === 0 &&
Object.keys(nonSignalSpecificHeaders).length === 0) {
return undefined;
}
const mergeHeaders = Object.assign({}, nonSignalSpecificHeaders, signalSpecificHeaders);
const metadata = (0, grpc_exporter_transport_1.createEmptyMetadata)();
// for this to work, metadata MUST be empty - otherwise `Metadata#set()` will merge items.
for (const [key, value] of Object.entries(mergeHeaders)) {
metadata.set(key, value);
}
return metadata;
}
function getMetadataProviderFromEnv(signalIdentifier) {
const metadata = getMetadataFromEnv(signalIdentifier);
if (metadata == null) {
return undefined;
}
return () => metadata;
}
function getUrlFromEnv(signalIdentifier) {
// This does not change the string beyond trimming on purpose.
// Normally a user would just use a host and port for gRPC, but the OTLP Exporter specification requires us to
// use the raw provided endpoint to derive credential settings. Therefore, we only normalize right when
// we merge user-provided, env-provided and defaults together, and we have determined which credentials to use.
//
// Examples:
// - example.test:4317 -> use secure credentials from environment (or provided via code)
// - http://example.test:4317 -> use insecure credentials if nothing else is provided
// - https://example.test:4317 -> use secure credentials from environment (or provided via code)
const specificEndpoint = process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`]?.trim();
const nonSpecificEndpoint = process.env[`OTEL_EXPORTER_OTLP_ENDPOINT`]?.trim();
return fallbackIfNullishOrBlank(specificEndpoint, nonSpecificEndpoint);
}
/**
* Determines whether the env var for insecure credentials is set to {@code true}.
*
* It will allow the following values as {@code true}
* - 'true'
* - 'true '
* - ' true'
* - 'TrUE'
* - 'TRUE'
*
* It will not allow:
* - 'true false'
* - 'false true'
* - 'true!'
* - 'true,true'
* - '1'
* - ' '
*
* @param signalIdentifier
*/
function getInsecureSettingFromEnv(signalIdentifier) {
const signalSpecificInsecureValue = process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_INSECURE`]
?.toLowerCase()
.trim();
const nonSignalSpecificInsecureValue = process.env[`OTEL_EXPORTER_OTLP_INSECURE`]
?.toLowerCase()
.trim();
return (fallbackIfNullishOrBlank(signalSpecificInsecureValue, nonSignalSpecificInsecureValue) === 'true');
}
function readFileFromEnv(signalSpecificEnvVar, nonSignalSpecificEnvVar, warningMessage) {
const signalSpecificPath = process.env[signalSpecificEnvVar]?.trim();
const nonSignalSpecificPath = process.env[nonSignalSpecificEnvVar]?.trim();
const filePath = fallbackIfNullishOrBlank(signalSpecificPath, nonSignalSpecificPath);
if (filePath != null) {
try {
return fs.readFileSync(path.resolve(process.cwd(), filePath));
}
catch {
api_1.diag.warn(warningMessage);
return undefined;
}
}
else {
return undefined;
}
}
function getClientCertificateFromEnv(signalIdentifier) {
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_CERTIFICATE`, 'OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE', 'Failed to read client certificate chain file');
}
function getClientKeyFromEnv(signalIdentifier) {
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_KEY`, 'OTEL_EXPORTER_OTLP_CLIENT_KEY', 'Failed to read client certificate private key file');
}
function getRootCertificateFromEnv(signalIdentifier) {
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CERTIFICATE`, 'OTEL_EXPORTER_OTLP_CERTIFICATE', 'Failed to read root certificate file');
}
function getCredentialsFromEnvIgnoreInsecure(signalIdentifier) {
const clientKey = getClientKeyFromEnv(signalIdentifier);
const clientCertificate = getClientCertificateFromEnv(signalIdentifier);
const rootCertificate = getRootCertificateFromEnv(signalIdentifier);
// if the chain is not intact, @grpc/grpc-js will throw. This is fine when a user provides it in code, but env var
// config is not allowed to throw, so we add this safeguard and try to make the best of it here.
const clientChainIntact = clientKey != null && clientCertificate != null;
if (rootCertificate != null && !clientChainIntact) {
api_1.diag.warn('Client key and certificate must both be provided, but one was missing - attempting to create credentials from just the root certificate');
return (0, grpc_exporter_transport_1.createSslCredentials)(getRootCertificateFromEnv(signalIdentifier));
}
return (0, grpc_exporter_transport_1.createSslCredentials)(rootCertificate, clientKey, clientCertificate);
}
function getCredentialsFromEnv(signalIdentifier) {
if (getInsecureSettingFromEnv(signalIdentifier)) {
return (0, grpc_exporter_transport_1.createInsecureCredentials)();
}
return getCredentialsFromEnvIgnoreInsecure(signalIdentifier);
}
function getOtlpGrpcConfigurationFromEnv(signalIdentifier) {
return {
...(0, node_http_1.getSharedConfigurationFromEnvironment)(signalIdentifier),
metadata: getMetadataProviderFromEnv(signalIdentifier),
url: getUrlFromEnv(signalIdentifier),
credentials: (finalResolvedUrl) => {
// Always assume insecure on http:// and secure on https://, the protocol always takes precedence over the insecure setting.
// note: the spec does not make any exception for
// - "localhost:4317". If the protocol is omitted, credentials are required unless insecure is set
// - "unix://", as it's neither http:// nor https:// and therefore credentials are required unless insecure is set
if (finalResolvedUrl.startsWith('http://')) {
return () => {
return (0, grpc_exporter_transport_1.createInsecureCredentials)();
};
}
else if (finalResolvedUrl.startsWith('https://')) {
return () => {
return getCredentialsFromEnvIgnoreInsecure(signalIdentifier);
};
}
// defer to env settings in this case
return () => {
return getCredentialsFromEnv(signalIdentifier);
};
},
};
}
exports.getOtlpGrpcConfigurationFromEnv = getOtlpGrpcConfigurationFromEnv;
//# sourceMappingURL=otlp-grpc-env-configuration.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import * as grpc from '@grpc/grpc-js';
/**
* Creates a unary service client constructor that, when instantiated, does not serialize/deserialize anything.
* Allows for passing in {@link Buffer} directly, serialization can be handled via protobufjs or custom implementations.
*
* @param path service path
* @param name service name
*/
export declare function createServiceClientConstructor(path: string, name: string): grpc.ServiceClientConstructor;
//# sourceMappingURL=create-service-client-constructor.d.ts.map

View File

@@ -0,0 +1,50 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServiceClientConstructor = void 0;
const grpc = require("@grpc/grpc-js");
/**
* Creates a unary service client constructor that, when instantiated, does not serialize/deserialize anything.
* Allows for passing in {@link Buffer} directly, serialization can be handled via protobufjs or custom implementations.
*
* @param path service path
* @param name service name
*/
function createServiceClientConstructor(path, name) {
const serviceDefinition = {
export: {
path: path,
requestStream: false,
responseStream: false,
requestSerialize: (arg) => {
return arg;
},
requestDeserialize: (arg) => {
return arg;
},
responseSerialize: (arg) => {
return arg;
},
responseDeserialize: (arg) => {
return arg;
},
},
};
return grpc.makeGenericClientConstructor(serviceDefinition, name);
}
exports.createServiceClientConstructor = createServiceClientConstructor;
//# sourceMappingURL=create-service-client-constructor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"create-service-client-constructor.js","sourceRoot":"","sources":["../../src/create-service-client-constructor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,sCAAsC;AAEtC;;;;;;GAMG;AACH,SAAgB,8BAA8B,CAC5C,IAAY,EACZ,IAAY;IAEZ,MAAM,iBAAiB,GAAG;QACxB,MAAM,EAAE;YACN,IAAI,EAAE,IAAI;YACV,aAAa,EAAE,KAAK;YACpB,cAAc,EAAE,KAAK;YACrB,gBAAgB,EAAE,CAAC,GAAW,EAAE,EAAE;gBAChC,OAAO,GAAG,CAAC;YACb,CAAC;YACD,kBAAkB,EAAE,CAAC,GAAW,EAAE,EAAE;gBAClC,OAAO,GAAG,CAAC;YACb,CAAC;YACD,iBAAiB,EAAE,CAAC,GAAW,EAAE,EAAE;gBACjC,OAAO,GAAG,CAAC;YACb,CAAC;YACD,mBAAmB,EAAE,CAAC,GAAW,EAAE,EAAE;gBACnC,OAAO,GAAG,CAAC;YACb,CAAC;SACF;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,4BAA4B,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;AACpE,CAAC;AAzBD,wEAyBC","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';\n\n/**\n * Creates a unary service client constructor that, when instantiated, does not serialize/deserialize anything.\n * Allows for passing in {@link Buffer} directly, serialization can be handled via protobufjs or custom implementations.\n *\n * @param path service path\n * @param name service name\n */\nexport function createServiceClientConstructor(\n path: string,\n name: string\n): grpc.ServiceClientConstructor {\n const serviceDefinition = {\n export: {\n path: path,\n requestStream: false,\n responseStream: false,\n requestSerialize: (arg: Buffer) => {\n return arg;\n },\n requestDeserialize: (arg: Buffer) => {\n return arg;\n },\n responseSerialize: (arg: Buffer) => {\n return arg;\n },\n responseDeserialize: (arg: Buffer) => {\n return arg;\n },\n },\n };\n\n return grpc.makeGenericClientConstructor(serviceDefinition, name);\n}\n"]}

View File

@@ -0,0 +1,39 @@
/// <reference types="node" />
import type { Metadata, ChannelCredentials } from '@grpc/grpc-js';
import { ExportResponse, IExporterTransport } from '@opentelemetry/otlp-exporter-base';
export declare function createInsecureCredentials(): ChannelCredentials;
export declare function createSslCredentials(rootCert?: Buffer, privateKey?: Buffer, certChain?: Buffer): ChannelCredentials;
export declare function createEmptyMetadata(): Metadata;
export interface GrpcExporterTransportParameters {
grpcPath: string;
grpcName: string;
address: string;
/**
* NOTE: Ensure that you're only importing/requiring gRPC inside the function providing the channel credentials,
* otherwise, gRPC and http/https instrumentations may break.
*
* For common cases, you can avoid to import/require gRPC your function by using
* - {@link createSslCredentials}
* - {@link createInsecureCredentials}
*/
credentials: () => ChannelCredentials;
/**
* NOTE: Ensure that you're only importing/requiring gRPC inside the function providing the metadata,
* otherwise, gRPC and http/https instrumentations may break.
*
* To avoid having to import/require gRPC from your function to create a new Metadata object,
* use {@link createEmptyMetadata}
*/
metadata: () => Metadata;
compression: 'gzip' | 'none';
}
export declare class GrpcExporterTransport implements IExporterTransport {
private _parameters;
private _client?;
private _metadata?;
constructor(_parameters: GrpcExporterTransportParameters);
shutdown(): void;
send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse>;
}
export declare function createOtlpGrpcExporterTransport(options: GrpcExporterTransportParameters): IExporterTransport;
//# sourceMappingURL=grpc-exporter-transport.d.ts.map

View File

@@ -0,0 +1,122 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOtlpGrpcExporterTransport = exports.GrpcExporterTransport = exports.createEmptyMetadata = exports.createSslCredentials = exports.createInsecureCredentials = void 0;
// values taken from '@grpc/grpc-js` so that we don't need to require/import it.
const GRPC_COMPRESSION_NONE = 0;
const GRPC_COMPRESSION_GZIP = 2;
function toGrpcCompression(compression) {
return compression === 'gzip' ? GRPC_COMPRESSION_GZIP : GRPC_COMPRESSION_NONE;
}
function createInsecureCredentials() {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const { credentials,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('@grpc/grpc-js');
return credentials.createInsecure();
}
exports.createInsecureCredentials = createInsecureCredentials;
function createSslCredentials(rootCert, privateKey, certChain) {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const { credentials,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('@grpc/grpc-js');
return credentials.createSsl(rootCert, privateKey, certChain);
}
exports.createSslCredentials = createSslCredentials;
function createEmptyMetadata() {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const { Metadata,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('@grpc/grpc-js');
return new Metadata();
}
exports.createEmptyMetadata = createEmptyMetadata;
class GrpcExporterTransport {
_parameters;
_client;
_metadata;
constructor(_parameters) {
this._parameters = _parameters;
}
shutdown() {
this._client?.close();
}
send(data, timeoutMillis) {
// We need to make a for gRPC
const buffer = Buffer.from(data);
if (this._client == null) {
// Lazy require to ensure that grpc is not loaded before instrumentations can wrap it
const { createServiceClientConstructor,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./create-service-client-constructor');
try {
this._metadata = this._parameters.metadata();
}
catch (error) {
return Promise.resolve({
status: 'failure',
error: error,
});
}
const clientConstructor = createServiceClientConstructor(this._parameters.grpcPath, this._parameters.grpcName);
try {
this._client = new clientConstructor(this._parameters.address, this._parameters.credentials(), {
'grpc.default_compression_algorithm': toGrpcCompression(this._parameters.compression),
});
}
catch (error) {
return Promise.resolve({
status: 'failure',
error: error,
});
}
}
return new Promise(resolve => {
const deadline = Date.now() + timeoutMillis;
// this should never happen
if (this._metadata == null) {
return resolve({
error: new Error('metadata was null'),
status: 'failure',
});
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore The gRPC client constructor is created on runtime, so we don't have any types for the resulting client.
this._client.export(buffer, this._metadata, { deadline: deadline }, (err, response) => {
if (err) {
resolve({
status: 'failure',
error: err,
});
}
else {
resolve({
data: response,
status: 'success',
});
}
});
});
}
}
exports.GrpcExporterTransport = GrpcExporterTransport;
function createOtlpGrpcExporterTransport(options) {
return new GrpcExporterTransport(options);
}
exports.createOtlpGrpcExporterTransport = createOtlpGrpcExporterTransport;
//# sourceMappingURL=grpc-exporter-transport.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
export { convertLegacyOtlpGrpcOptions } from './configuration/convert-legacy-otlp-grpc-options';
export { createOtlpGrpcExportDelegate } from './otlp-grpc-export-delegate';
export { OTLPGRPCExporterConfigNode } from './types';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,23 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOtlpGrpcExportDelegate = exports.convertLegacyOtlpGrpcOptions = void 0;
var convert_legacy_otlp_grpc_options_1 = require("./configuration/convert-legacy-otlp-grpc-options");
Object.defineProperty(exports, "convertLegacyOtlpGrpcOptions", { enumerable: true, get: function () { return convert_legacy_otlp_grpc_options_1.convertLegacyOtlpGrpcOptions; } });
var otlp_grpc_export_delegate_1 = require("./otlp-grpc-export-delegate");
Object.defineProperty(exports, "createOtlpGrpcExportDelegate", { enumerable: true, get: function () { return otlp_grpc_export_delegate_1.createOtlpGrpcExportDelegate; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,qGAAgG;AAAvF,gJAAA,4BAA4B,OAAA;AACrC,yEAA2E;AAAlE,yIAAA,4BAA4B,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 { convertLegacyOtlpGrpcOptions } from './configuration/convert-legacy-otlp-grpc-options';\nexport { createOtlpGrpcExportDelegate } from './otlp-grpc-export-delegate';\nexport { OTLPGRPCExporterConfigNode } from './types';\n"]}

View File

@@ -0,0 +1,5 @@
import { IOtlpExportDelegate } from '@opentelemetry/otlp-exporter-base';
import { ISerializer } from '@opentelemetry/otlp-transformer';
import { OtlpGrpcConfiguration } from './configuration/otlp-grpc-configuration';
export declare function createOtlpGrpcExportDelegate<Internal, Response>(options: OtlpGrpcConfiguration, serializer: ISerializer<Internal, Response>, grpcName: string, grpcPath: string): IOtlpExportDelegate<Internal>;
//# sourceMappingURL=otlp-grpc-export-delegate.d.ts.map

View File

@@ -0,0 +1,32 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOtlpGrpcExportDelegate = void 0;
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const grpc_exporter_transport_1 = require("./grpc-exporter-transport");
function createOtlpGrpcExportDelegate(options, serializer, grpcName, grpcPath) {
return (0, otlp_exporter_base_1.createOtlpNetworkExportDelegate)(options, serializer, (0, grpc_exporter_transport_1.createOtlpGrpcExporterTransport)({
address: options.url,
compression: options.compression,
credentials: options.credentials,
metadata: options.metadata,
grpcName,
grpcPath,
}));
}
exports.createOtlpGrpcExportDelegate = createOtlpGrpcExportDelegate;
//# sourceMappingURL=otlp-grpc-export-delegate.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"otlp-grpc-export-delegate.js","sourceRoot":"","sources":["../../src/otlp-grpc-export-delegate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0EAG2C;AAG3C,uEAA4E;AAE5E,SAAgB,4BAA4B,CAC1C,OAA8B,EAC9B,UAA2C,EAC3C,QAAgB,EAChB,QAAgB;IAEhB,OAAO,IAAA,oDAA+B,EACpC,OAAO,EACP,UAAU,EACV,IAAA,yDAA+B,EAAC;QAC9B,OAAO,EAAE,OAAO,CAAC,GAAG;QACpB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,QAAQ;QACR,QAAQ;KACT,CAAC,CACH,CAAC;AACJ,CAAC;AAlBD,oEAkBC","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 {\n createOtlpNetworkExportDelegate,\n IOtlpExportDelegate,\n} from '@opentelemetry/otlp-exporter-base';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\nimport { OtlpGrpcConfiguration } from './configuration/otlp-grpc-configuration';\nimport { createOtlpGrpcExporterTransport } from './grpc-exporter-transport';\n\nexport function createOtlpGrpcExportDelegate<Internal, Response>(\n options: OtlpGrpcConfiguration,\n serializer: ISerializer<Internal, Response>,\n grpcName: string,\n grpcPath: string\n): IOtlpExportDelegate<Internal> {\n return createOtlpNetworkExportDelegate(\n options,\n serializer,\n createOtlpGrpcExporterTransport({\n address: options.url,\n compression: options.compression,\n credentials: options.credentials,\n metadata: options.metadata,\n grpcName,\n grpcPath,\n })\n );\n}\n"]}

View File

@@ -0,0 +1,11 @@
import type { ChannelCredentials, Metadata } from '@grpc/grpc-js';
import { CompressionAlgorithm, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
/**
* OTLP Exporter Config for Node
*/
export interface OTLPGRPCExporterConfigNode extends OTLPExporterConfigBase {
credentials?: ChannelCredentials;
metadata?: Metadata;
compression?: CompressionAlgorithm;
}
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1,18 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","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 type { ChannelCredentials, Metadata } from '@grpc/grpc-js';\n\nimport {\n CompressionAlgorithm,\n OTLPExporterConfigBase,\n} from '@opentelemetry/otlp-exporter-base';\n\n/**\n * OTLP Exporter Config for Node\n */\nexport interface OTLPGRPCExporterConfigNode extends OTLPExporterConfigBase {\n credentials?: ChannelCredentials;\n metadata?: Metadata;\n compression?: CompressionAlgorithm;\n}\n"]}

View File

@@ -0,0 +1,2 @@
export declare const VERSION = "0.200.0";
//# sourceMappingURL=version.d.ts.map

View File

@@ -0,0 +1,21 @@
"use strict";
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.200.0';
//# sourceMappingURL=version.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,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.200.0';\n"]}