Merge pull request #28185 from alloy/update-dd-trace

[dd-trace] Update for 0.5.x
This commit is contained in:
Eloy Durán
2018-08-20 15:15:54 +02:00
committed by GitHub
5 changed files with 53 additions and 180 deletions
+14 -4
View File
@@ -1,7 +1,7 @@
import * as ddTrace from 'dd-trace';
import SpanContext = require('dd-trace/src/opentracing/span_context');
import * as tracer from 'dd-trace';
import { SpanContext } from 'opentracing';
const tracer = ddTrace.init({
tracer.init({
service: 'MyLovelyService',
hostname: 'localhost',
port: 8126,
@@ -14,7 +14,7 @@ const tracer = ddTrace.init({
tracer
.trace('web.request', {
service: 'my_service',
childOf: new SpanContext({ traceId: 1337, spanId: 42 }),
childOf: new SpanContext(),
tags: {
env: 'dev'
}
@@ -23,3 +23,13 @@ tracer
span.setTag('my_tag', 'my_value');
span.finish();
});
const parentScope = tracer.scopeManager().active();
const span = tracer.startSpan('memcached', {
childOf: parentScope && parentScope.span(),
tags: {
'service.name': 'my-memcached',
'resource.name': 'get',
'span.type': 'memcached',
},
});
+39 -4
View File
@@ -1,11 +1,10 @@
// Type definitions for dd-trace-js 0.2
// Type definitions for dd-trace-js 0.5
// Project: https://github.com/DataDog/dd-trace-js
// Definitions by: Colin Bradley <https://github.com/ColinBradley>
// Eloy Durán <https://github.com/alloy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import Tracer = require('./src/opentracing/tracer');
import Span = require('./src/opentracing/span');
import SpanContext = require('./src/opentracing/span_context');
import { Tracer, Span, SpanContext } from "opentracing";
declare var trace: TraceProxy;
export = trace;
@@ -42,6 +41,11 @@ declare class TraceProxy extends Tracer {
* @returns The current span or null if outside a trace context.
*/
currentSpan(): Span | null;
/**
* Get the scope manager to manager context propagation for the tracer.
*/
scopeManager(): ScopeManager;
}
interface TracerOptions {
@@ -147,3 +151,34 @@ interface TraceOptions {
*/
tags?: { [key: string]: any } | string;
}
declare class ScopeManager {
/**
* Get the current active scope or null if there is none.
*
* @todo The dd-trace source returns null, but opentracing's childOf span
* option is typed as taking undefined or a scope, so using undefined
* here instead.
*/
active(): Scope | undefined;
/**
* Activate a new scope wrapping the provided span.
*
* @param span The span for which to activate the new scope.
* @param finishSpanOnClose Whether to automatically finish the span when the scope is closed.
*/
activate(span: Span, finishSpanOnClose?: boolean): Scope;
}
declare class Scope {
/**
* Get the span wrapped by this scope.
*/
span(): Span;
/**
* Close the scope, and finish the span if the scope was created with `finishSpanOnClose` set to true.
*/
close(): void;
}
-121
View File
@@ -1,121 +0,0 @@
import Tracer = require('./tracer');
import SpanContext = require('./span_context');
import { Span } from 'opentracing';
declare class DatadogSpan extends Span {
/**
* Returns the SpanContext object associated with this Span.
*/
context(): SpanContext;
/**
* Returns the Tracer object used to create this Span.
*/
tracer(): Tracer;
/**
* Sets the string name for the logical operation this span represents.
*/
setOperationName(name: string): this;
/**
* Sets a key:value pair on this Span that also propagates to future
* children of the associated Span.
*
* setBaggageItem() enables powerful functionality given a full-stack
* opentracing integration (e.g., arbitrary application data from a web
* client can make it, transparently, all the way into the depths of a
* storage system), and with it some powerful costs: use this feature with
* care.
*
* IMPORTANT NOTE #1: setBaggageItem() will only propagate baggage items to
* *future* causal descendants of the associated Span.
*
* IMPORTANT NOTE #2: Use this thoughtfully and with care. Every key and
* value is copied into every local *and remote* child of the associated
* Span, and that can add up to a lot of network and cpu overhead.
*/
setBaggageItem(key: string, value: string): this;
/**
* Returns the value for a baggage item given its key.
*
* @param key
* The key for the given trace attribute.
* @return String value for the given key, or undefined if the key does not
* correspond to a set trace attribute.
*/
getBaggageItem(key: string): string | undefined;
/**
* Adds a single tag to the span. See `addTags()` for details.
*/
setTag(key: string, value: any): this;
/**
* Adds the given key value pairs to the set of span tags.
*
* Multiple calls to addTags() results in the tags being the superset of
* all calls.
*
* The behavior of setting the same key multiple times on the same span
* is undefined.
*
* The supported type of the values is implementation-dependent.
* Implementations are expected to safely handle all types of values but
* may choose to ignore unrecognized / unhandle-able values (e.g. objects
* with cyclic references, function objects).
*/
addTags(keyValueMap: {
[key: string]: any;
}): this;
/**
* Add a log record to this Span, optionally at a user-provided timestamp.
*
* For example:
*
* span.log({
* size: rpc.size(), // numeric value
* URI: rpc.URI(), // string value
* payload: rpc.payload(), // Object value
* "keys can be arbitrary strings": rpc.foo(),
* });
*
* span.log({
* "error.description": someError.description(),
* }, someError.timestampMillis());
*
* @param keyValuePairs
* An object mapping string keys to arbitrary value types. All
* Tracer implementations should support bool, string, and numeric
* value types, and some may also support Object values.
* @param timestamp
* An optional parameter specifying the timestamp in milliseconds
* since the Unix epoch. Fractional values are allowed so that
* timestamps with sub-millisecond accuracy can be represented. If
* not specified, the implementation is expected to use its notion
* of the current time of the call.
*/
log(keyValuePairs: {
[key: string]: any;
}, timestamp?: number): this;
/**
* Sets the end timestamp and finalizes Span state.
*
* With the exception of calls to Span.context() (which are always allowed),
* finish() must be the last call made to any span instance, and to do
* otherwise leads to undefined behavior.
*
* @param finishTime
* Optional finish time in milliseconds as a Unix timestamp. Decimal
* values are supported for timestamps with sub-millisecond accuracy.
* If not specified, the current time (as defined by the
* implementation) will be used.
*/
finish(finishTime?: number): void;
}
export = DatadogSpan;
-40
View File
@@ -1,40 +0,0 @@
import { SpanContext } from 'opentracing';
/**
* SpanContext represents Span state that must propagate to descendant Spans
* and across process boundaries.
*
* SpanContext is logically divided into two pieces: the user-level "Baggage"
* (see setBaggageItem and getBaggageItem) that propagates across Span
* boundaries and any Tracer-implementation-specific fields that are needed to
* identify or otherwise contextualize the associated Span instance (e.g., a
* <trace_id, span_id, sampled> tuple).
*/
declare class DatadogSpanContext extends SpanContext {
/**
* Use to create references to parent spans.
*/
constructor(props: SpanContextLike);
public traceId: number;
public spanId: number;
public parentId?: number | null;
public sampled?: boolean;
public baggageItems?: { [key: string]: string };
public trace?: {
started: number[],
finished: number[]
}
}
interface SpanContextLike {
traceId: number;
spanId: number;
}
export = DatadogSpanContext;
-11
View File
@@ -1,11 +0,0 @@
import { Tracer } from 'opentracing';
/**
* Tracer is the entry-point between the instrumentation API and the tracing
* implementation.
*/
declare class DatadogTracer extends Tracer {
}
export = DatadogTracer;