Skip to content

Commit

Permalink
fix(opentelemetry-exporter-jaeger): adds header to avoid infinity loop
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodalcin committed Apr 17, 2020
1 parent 5de0fba commit 256eb0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/opentelemetry-exporter-jaeger/src/jaeger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing';
import { Socket } from 'dgram';
import { spanToThrift } from './transform';
import * as jaegerTypes from './types';
import { OT_REQUEST_HEADER } from './utils';

/**
* Format and sends span information to Jaeger Exporter.
Expand All @@ -46,10 +47,13 @@ export class JaegerExporter implements SpanExporter {
// JAEGER_AGENT_PORT to send UDP traces to a different host:port. If JAEGER_ENDPOINT is set, the client sends traces
// to the endpoint via HTTP, making the JAEGER_AGENT_HOST and JAEGER_AGENT_PORT unused. If JAEGER_ENDPOINT is secured,
// HTTP basic authentication can be performed by setting the JAEGER_USER and JAEGER_PASSWORD environment variables.
this._sender = config.endpoint
? new jaegerTypes.HTTPSender(config)
: new jaegerTypes.UDPSender(config);
this._sender = new jaegerTypes.UDPSender(config);
if (config.endpoint) {
this._sender = new jaegerTypes.HTTPSender(config);
this._sender._httpOptions.headers[OT_REQUEST_HEADER] = 1;
} else {
this._sender = config.endpoint = new jaegerTypes.UDPSender(config);
}

if (this._sender._client instanceof Socket) {
// unref socket to prevent it from keeping the process running
this._sender._client.unref();
Expand Down
17 changes: 17 additions & 0 deletions packages/opentelemetry-exporter-jaeger/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
* Copyright 2020, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const OT_REQUEST_HEADER = 'x-opentelemetry-outgoing-request';

0 comments on commit 256eb0e

Please sign in to comment.