HTTP_PROXY env vars and exporter-trace-otlp-http #3490
-
I have an nestjs API that requires that HTTP_PROXY and HTTPS_PROXY env vars are set in order to use the proxy for its functionality. Here is my tracing.js file, if it helps. import {
CompositePropagator,
W3CTraceContextPropagator,
W3CBaggagePropagator,
} from '@opentelemetry/core';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Attributes, Context, diag, DiagConsoleLogger, DiagLogLevel, Link, SpanKind } from '@opentelemetry/api';
import { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston';
import { Sampler, SamplingResult, SamplingDecision } from "@opentelemetry/sdk-trace-base";
import { FileTraceExporter } from "opentelemetry-exporter-trace-otlp-file";
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
import config from 'config';
const process = require('process');
export class DemoSampler implements Sampler {
shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes, links: Link[]): SamplingResult {
if (spanName.includes('healthcheck')) {
return {
decision: SamplingDecision.NOT_RECORD
}
} else {
return {
decision: SamplingDecision.RECORD_AND_SAMPLED
}
}
}
getDescription() {
return "DemoSampler";
}
}
const collector: string = config.get('collector.url');
const traceCollectorOptions = {
url: collector,
};
const apiName: string = config.get('api.name');
const spanExporter = new OTLPTraceExporter(traceCollectorOptions);
const otelSDK = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: apiName,
}),
contextManager: new AsyncLocalStorageContextManager(),
textMapPropagator: new CompositePropagator({
propagators: [
new W3CTraceContextPropagator(),
new W3CBaggagePropagator(),
],
}),
instrumentations: [
new NestInstrumentation(),
new WinstonInstrumentation(),
],
sampler: new DemoSampler()
});
export default otelSDK;
process.on('SIGTERM', () => {
otelSDK
.shutdown()
.then(
() => console.log('SDK shut down successfully'),
(err) => console.log('Error shutting down SDK', err),
)
.finally(() => process.exit(0));
}); My main.ts file imports this tracing file and starts it to collect the traces. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
We are not doing anything to specifically support HTTP_PROXY or HTTPS_PROXY and as far as I know, node doesn't support that behavior out of the box. This may be behavior caused by nest itself. I'm not sure if there's any way we can prevent it. |
Beta Was this translation helpful? Give feedback.
-
@samuellvicente i know this issue is kind of old but did you find a way to fix this? We also use NestJS and have the same issue. |
Beta Was this translation helpful? Give feedback.
We are not doing anything to specifically support HTTP_PROXY or HTTPS_PROXY and as far as I know, node doesn't support that behavior out of the box. This may be behavior caused by nest itself. I'm not sure if there's any way we can prevent it.