Skip to content

Commit

Permalink
ci: gts fix for ci build
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Albertini <[email protected]>
  • Loading branch information
OlivierAlbertini committed Aug 6, 2019
1 parent 284aaeb commit bfbf65d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 39 deletions.
19 changes: 14 additions & 5 deletions packages/opentelemetry-basic-tracer/src/BasicTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
*/

import * as types from '@opentelemetry/types';
import { ALWAYS_SAMPLER, BinaryTraceContext, HttpTraceContext, NOOP_SPAN } from '@opentelemetry/core';
import {
ALWAYS_SAMPLER,
BinaryTraceContext,
HttpTraceContext,
NOOP_SPAN,
} from '@opentelemetry/core';
import { BinaryFormat, HttpTextFormat } from '@opentelemetry/types';
import { BasicTracerConfig } from '../src/types';
import { ScopeManager } from '@opentelemetry/scope-base';
Expand All @@ -29,7 +34,6 @@ export class BasicTracer implements types.Tracer {
private readonly _binaryFormat: types.BinaryFormat;
private readonly _httpTextFormat: types.HttpTextFormat;
private readonly _sampler: types.Sampler;

protected readonly _scopeManager: ScopeManager;

/**
Expand Down Expand Up @@ -57,7 +61,7 @@ export class BasicTracer implements types.Tracer {
}

const spanOptions = Object.assign({}, options, {
parent: parentSpanContext
parent: parentSpanContext,
});
const span = new Span(this, name, spanOptions);

Expand All @@ -77,7 +81,10 @@ export class BasicTracer implements types.Tracer {
/**
* Enters the scope of code where the given Span is in the current context.
*/
withSpan<T extends (...args: unknown[]) => ReturnType<T>>(span: types.Span, fn: T): ReturnType<T> {
withSpan<T extends (...args: unknown[]) => ReturnType<T>>(
span: types.Span,
fn: T
): ReturnType<T> {
// Set given span to context.
return this._scopeManager.with(span, fn);
}
Expand All @@ -103,7 +110,9 @@ export class BasicTracer implements types.Tracer {
return this._httpTextFormat;
}

private _getParentSpanContext(parent: types.Span | types.SpanContext | undefined): types.SpanContext | undefined {
private _getParentSpanContext(
parent: types.Span | types.SpanContext | undefined
): types.SpanContext | undefined {
if (!parent) return undefined;

// parent is a SpanContext
Expand Down
4 changes: 3 additions & 1 deletion packages/opentelemetry-node-tracer/src/NodeTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class NodeTracer extends BasicTracer {
* Constructs a new Tracer instance.
*/
constructor(config: BasicTracerConfig) {
super(Object.assign({}, { scopeManager: new AsyncHooksScopeManager() }, config));
super(
Object.assign({}, { scopeManager: new AsyncHooksScopeManager() }, config)
);

// @todo: Integrate Plugin Loader (pull/126).
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-node-tracer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './NodeTracer';
export * from './NodeTracer';
37 changes: 20 additions & 17 deletions packages/opentelemetry-node-tracer/test/NodeTracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
HttpTraceContext,
NEVER_SAMPLER,
NoopLogger,
NOOP_SPAN
NOOP_SPAN,
} from '@opentelemetry/core';
import { AsyncHooksScopeManager } from '@opentelemetry/scope-async-hooks';
import { NodeTracer } from '../src/NodeTracer';
Expand All @@ -31,39 +31,39 @@ describe('NodeTracer', () => {
describe('constructor', () => {
it('should construct an instance with required only options', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer instanceof NodeTracer);
});

it('should construct an instance with binary format', () => {
const tracer = new NodeTracer({
binaryFormat: new BinaryTraceContext(),
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer instanceof NodeTracer);
});

it('should construct an instance with http text format', () => {
const tracer = new NodeTracer({
httpTextFormat: new HttpTraceContext(),
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer instanceof NodeTracer);
});

it('should construct an instance with logger', () => {
const tracer = new NodeTracer({
logger: new NoopLogger(),
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer instanceof NodeTracer);
});

it('should construct an instance with sampler', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager(),
sampler: ALWAYS_SAMPLER
sampler: ALWAYS_SAMPLER,
});
assert.ok(tracer instanceof NodeTracer);
});
Expand All @@ -72,9 +72,9 @@ describe('NodeTracer', () => {
const tracer = new NodeTracer({
defaultAttributes: {
region: 'eu-west',
asg: 'my-asg'
asg: 'my-asg',
},
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer instanceof NodeTracer);
});
Expand All @@ -83,15 +83,15 @@ describe('NodeTracer', () => {
describe('.startSpan()', () => {
it('should start a span with name only', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
const span = tracer.startSpan('my-span');
assert.ok(span);
});

it('should start a span with name and options', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
const span = tracer.startSpan('my-span', {});
assert.ok(span);
Expand All @@ -100,7 +100,7 @@ describe('NodeTracer', () => {
it('should return a default span with no sampling', () => {
const tracer = new NodeTracer({
sampler: NEVER_SAMPLER,
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
const span = tracer.startSpan('my-span');
assert.deepStrictEqual(span, NOOP_SPAN);
Expand All @@ -116,7 +116,7 @@ describe('NodeTracer', () => {
describe('.getCurrentSpan()', () => {
it('should return null with AsyncHooksScopeManager when no span started', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.deepStrictEqual(tracer.getCurrentSpan(), null);
});
Expand All @@ -125,7 +125,7 @@ describe('NodeTracer', () => {
describe('.withSpan()', () => {
it('should run scope with AsyncHooksScopeManager scope manager', done => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
const span = tracer.startSpan('my-span');
tracer.withSpan(span, () => {
Expand All @@ -137,7 +137,7 @@ describe('NodeTracer', () => {

it('should run scope with AsyncHooksScopeManager scope manager with multiple spans', done => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
const span = tracer.startSpan('my-span');
tracer.withSpan(span, () => {
Expand All @@ -146,7 +146,10 @@ describe('NodeTracer', () => {
const span1 = tracer.startSpan('my-span1', { parent: span });
tracer.withSpan(span1, () => {
assert.deepStrictEqual(tracer.getCurrentSpan(), span1);
assert.deepStrictEqual(span1.context().traceId, span.context().traceId);
assert.deepStrictEqual(
span1.context().traceId,
span.context().traceId
);
return done();
});
});
Expand All @@ -164,7 +167,7 @@ describe('NodeTracer', () => {
describe('getBinaryFormat', () => {
it('should get default binary formatter', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer.getBinaryFormat() instanceof BinaryTraceContext);
});
Expand All @@ -173,7 +176,7 @@ describe('NodeTracer', () => {
describe('.getHttpTextFormat()', () => {
it('should get default HTTP text formatter', () => {
const tracer = new NodeTracer({
scopeManager: new AsyncHooksScopeManager()
scopeManager: new AsyncHooksScopeManager(),
});
assert.ok(tracer.getHttpTextFormat() instanceof HttpTraceContext);
});
Expand Down
7 changes: 3 additions & 4 deletions packages/opentelemetry-plugin-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/scope-async-hooks": "^0.0.1",
"@types/mocha": "^5.2.7",
"@types/nock": "^10.0.3",
"@types/node": "^12.6.9",
"@types/semver": "^6.0.1",
"@types/shimmer": "^1.0.1",
"@types/sinon":"^7.0.13",
"@opentelemetry/scope-async-hooks": "^0.0.1",
"codecov": "^3.5.0",
"gts": "^1.1.0",
"gts": "^1.0.0",
"mocha": "^6.2.0",
"nock": "^10.0.6",
"nyc": "^14.1.1",
"sinon": "^7.3.2",
"c8": "^5.0.1",
"nock": "^10.0.6",
"ts-mocha": "^6.0.0",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http/src/enums/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export enum Attributes {
ATTRIBUTE_HTTP_STATUS_CODE = 'http.status_code',
// NOT ON OFFICIAL SPEC
ATTRIBUTE_HTTP_ERROR_NAME = 'http.error_name',
ATTRIBUTE_HTTP_ERROR_MESSAGE = 'http.error_message'
ATTRIBUTE_HTTP_ERROR_MESSAGE = 'http.error_message',
}
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http/src/enums/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Should we export this to the types package in order to expose all values ?
export enum Format {
HTTP = 'HttpTraceContext'
HTTP = 'HttpTraceContext',
}
8 changes: 4 additions & 4 deletions packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class HttpPlugin extends BasePlugin<Http> {
span.setAttributes({
ATTRIBUTE_HTTP_HOST: host,
ATTRIBUTE_HTTP_METHOD: method,
ATTRIBUTE_HTTP_PATH: options.path || '/'
ATTRIBUTE_HTTP_PATH: options.path || '/',
});

if (userAgent) {
Expand Down Expand Up @@ -203,7 +203,7 @@ export class HttpPlugin extends BasePlugin<Http> {
const headers = request.headers;

const spanOptions: SpanOptions = {
kind: SpanKind.SERVER
kind: SpanKind.SERVER,
};

const spanContext = propagation.extract(Format.HTTP, headers);
Expand Down Expand Up @@ -296,7 +296,7 @@ export class HttpPlugin extends BasePlugin<Http> {
const method = options.method ? options.method.toUpperCase() : 'GET';
const operationName = `${method} ${pathname}`;
const spanOptions = {
kind: SpanKind.CLIENT
kind: SpanKind.CLIENT,
};
const currentSpan = plugin._tracer.getCurrentSpan();
// Checks if this outgoing request is part of an operation by checking
Expand All @@ -311,7 +311,7 @@ export class HttpPlugin extends BasePlugin<Http> {
plugin._logger.debug('outgoingRequest starting a child span');
const span = plugin._tracer.startSpan(operationName, {
kind: spanOptions.kind,
parent: currentSpan
parent: currentSpan,
});
return plugin.getMakeRequestTraceFunction(request, options)(span);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-http/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Status, CanonicalCode, Span } from '@opentelemetry/types';
import { RequestOptions, IncomingMessage, ClientRequest } from 'http';
import { IgnoreMatcher } from './types';
import { Attributes } from './enums/Attributes';
import { Attributes } from './enums/attributes';
import * as url from 'url';

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Utils {
span.setAttributes({
[Attributes.ATTRIBUTE_ERROR]: true,
[Attributes.ATTRIBUTE_HTTP_ERROR_NAME]: error.name,
[Attributes.ATTRIBUTE_HTTP_ERROR_MESSAGE]: error.message
[Attributes.ATTRIBUTE_HTTP_ERROR_MESSAGE]: error.message,
});

let status: Status;
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-http/test/http-disable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const httpRequest = {
});
});
});
}
},
};

class DummyPropagation implements HttpTextFormat {
Expand All @@ -67,7 +67,7 @@ describe('HttpPlugin', () => {
const tracer = new NodeTracer({
scopeManager,
logger,
httpTextFormat
httpTextFormat,
});
before(() => {
plugin.enable(http, tracer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('HttpPlugin', () => {
const tracer = new NodeTracer({
scopeManager,
logger,
httpTextFormat
httpTextFormat,
});
before(() => {
plugin.enable(
Expand Down

0 comments on commit bfbf65d

Please sign in to comment.