Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(opentelemetry-exporter-jaeger): http sender #965

Merged
merged 24 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3942759
feat(opentelemetry-exporter-jaeger): http sender
leonardodalcin Apr 13, 2020
0408488
fix: linter
leonardodalcin Apr 13, 2020
5de0fba
Merge branch 'master' into http-sender
leonardodalcin Apr 14, 2020
256eb0e
fix(opentelemetry-exporter-jaeger): adds header to avoid infinity loop
leonardodalcin Apr 17, 2020
cf5fe82
Merge branch 'master' into http-sender
leonardodalcin Apr 17, 2020
2ef75b5
test(opentelemetry-exporter-jaeger): verify http sender usage
leonardodalcin Apr 17, 2020
a2ce058
Merge remote-tracking branch 'origin/http-sender' into http-sender
leonardodalcin Apr 17, 2020
0e1abfe
Merge branch 'master' into http-sender
leonardodalcin Apr 17, 2020
7e64566
refactor(opentelemetry-exporter-jaeger): checks if endpoint is setten
leonardodalcin Apr 20, 2020
0a15276
Merge branch 'master' into http-sender
leonardodalcin May 8, 2020
5620e16
feat(opentelemetry-exporter-jaeger): adds nock as dev dependency
leonardodalcin May 8, 2020
90f919e
test(opentelemetry-exporter-jaeger): adds tests to check req header
leonardodalcin May 8, 2020
b595b54
Merge remote-tracking branch 'origin/http-sender' into http-sender
leonardodalcin May 8, 2020
38dc850
fix: tests variable usage
leonardodalcin May 8, 2020
0235711
Merge branch 'master' into http-sender
mayurkale22 May 27, 2020
0d8b202
Merge branch 'master' into http-sender
leonardodalcin May 27, 2020
2c75792
refactor(opentelemetry-exporter-jaeger): removes config parameter change
leonardodalcin Jun 3, 2020
a528a1e
Merge branch 'master' into http-sender
leonardodalcin Jun 3, 2020
d284387
fix: linter
leonardodalcin Jun 3, 2020
8d51800
fix: env var was never called
leonardodalcin Jun 3, 2020
abcfcc7
Merge remote-tracking branch 'origin/http-sender' into http-sender
leonardodalcin Jun 3, 2020
9398254
Merge branch 'master' into http-sender
leonardodalcin Jun 9, 2020
69d3f13
Merge branch 'master' into http-sender
dyladan Jun 10, 2020
2e94c67
Merge branch 'master' into http-sender
mayurkale22 Jun 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion 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';
vmarchaud marked this conversation as resolved.
Show resolved Hide resolved

/**
* Format and sends span information to Jaeger Exporter.
Expand All @@ -38,8 +39,21 @@ export class JaegerExporter implements SpanExporter {
typeof config.flushTimeout === 'number' ? config.flushTimeout : 2000;

config.host = config.host || process.env.JAEGER_AGENT_HOST;
config.endpoint = config.endpoint || process.env.JAEGER_ENDPOINT;
config.username = config.username || process.env.JAEGER_USER;
config.password = config.password || process.env.JAEGER_PASSWORD;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I woud prefer to verify that one of username/password or endpoint is defined and valid to avoid runtime errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7e64566

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your commit, i think it's not possible to only use JAEGER_AGENT_ENDPOINT env var since you check for config.endpoint which should be undefined in this case. Is that normal ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If process.env.JAEGER_ENDPOINT is defined, then config.endpoint will also be. I don't think i understood what you meant.

// https://github.com/jaegertracing/jaeger-client-node#environment-variables
// By default, the client sends traces via UDP to the agent at localhost:6832. Use JAEGER_AGENT_HOST and
// 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.
if (config.endpoint) {
obecny marked this conversation as resolved.
Show resolved Hide resolved
this._sender = new jaegerTypes.HTTPSender(config);
this._sender._httpOptions.headers[OT_REQUEST_HEADER] = 1;
} else {
this._sender = config.endpoint = new jaegerTypes.UDPSender(config);
}

this._sender = 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
10 changes: 10 additions & 0 deletions packages/opentelemetry-exporter-jaeger/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export interface ExporterConfig {
maxPacketSize?: number; // default: 65000
/** Time to wait for an onShutdown flush to finish before closing the sender */
flushTimeout?: number; // default: 2000
//The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces
//If setten will override host and port
endpoint?: string;
//Username to send as part of "Basic" authentication to the collector endpoint
username?: string;
//Password to send as part of "Basic" authentication to the collector endpoint
password?: string;
}

// Below require is needed as jaeger-client types does not expose the thrift,
Expand All @@ -41,6 +48,9 @@ export const Utils = require('jaeger-client/dist/src/util').default;
// tslint:disable-next-line:variable-name
export const ThriftUtils = require('jaeger-client/dist/src/thrift').default;

export const HTTPSender = require('jaeger-client/dist/src/reporters/http_sender')
.default;

export type TagValue = string | number | boolean;

export interface Tag {
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';
13 changes: 13 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ReadableSpan } from '@opentelemetry/tracing';
import { ExportResult } from '@opentelemetry/base';
import { TraceFlags } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { OT_REQUEST_HEADER } from '../src/utils';

describe('JaegerExporter', () => {
describe('constructor', () => {
Expand Down Expand Up @@ -150,5 +151,17 @@ describe('JaegerExporter', () => {
assert.strictEqual(result, ExportResult.SUCCESS);
});
});

it('should use httpSender if config.endpoint is setten and set x-opentelemetry-outgoing-request header', () => {
dyladan marked this conversation as resolved.
Show resolved Hide resolved
const exporter = new JaegerExporter({
serviceName: 'opentelemetry',
endpoint: 'http://testendpoint',
});
assert.strictEqual(exporter['_sender'].constructor.name, 'HTTPSender');
assert.strictEqual(
exporter['_sender']._httpOptions.headers[OT_REQUEST_HEADER],
1
);
dyladan marked this conversation as resolved.
Show resolved Hide resolved
});
});
});