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 13 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
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-jaeger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^15.0.0",
"nock": "^12.0.3",
"rimraf": "^3.0.0",
"ts-mocha": "^6.0.0",
"ts-node": "^8.6.2",
Expand Down
18 changes: 16 additions & 2 deletions packages/opentelemetry-exporter-jaeger/src/jaeger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -36,9 +37,22 @@ export class JaegerExporter implements SpanExporter {
this._onShutdownFlushTimeout =
typeof config.flushTimeout === 'number' ? config.flushTimeout : 2000;

config.host = config.host || process.env.JAEGER_AGENT_HOST;
// 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
config.endpoint = config.endpoint || process.env.JAEGER_ENDPOINT;
obecny marked this conversation as resolved.
Show resolved Hide resolved
config.username = config.username || process.env.JAEGER_USER;
config.password = config.password || process.env.JAEGER_PASSWORD;
this._sender = new jaegerTypes.HTTPSender(config);
this._sender._httpOptions.headers[OT_REQUEST_HEADER] = 1;
} else {
config.host = config.host || process.env.JAEGER_AGENT_HOST;
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';
48 changes: 48 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { ThriftProcess } from '../src/types';
import { ReadableSpan } from '@opentelemetry/tracing';
import { TraceFlags } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { OT_REQUEST_HEADER } from '../src/utils';
import * as nock from 'nock';

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

it('should use httpSender if config.endpoint is setten and set x-opentelemetry-outgoing-request header', done => {
const mockedEndpoint = 'http://testendpoint';
nock(mockedEndpoint)
.post('/')
.reply(function() {
assert.strictEqual(this.req.headers[OT_REQUEST_HEADER], 1);
assert.strictEqual(
this.req.headers['content-type'],
'application/x-thrift'
);
assert.strictEqual(this.req.headers.host, 'testendpoint');
done();
});
const exporter = new JaegerExporter({
serviceName: 'opentelemetry',
endpoint: mockedEndpoint,
});
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
const spanContext = {
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.NONE,
};
const readableSpan: ReadableSpan = {
name: 'my-span1',
kind: types.SpanKind.CLIENT,
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
},
attributes: {},
links: [],
events: [],
duration: [32, 800000000],
resource: Resource.empty(),
};
exporter.export([readableSpan], () => {});
});
});
});