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

Fix ts errors #3912

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 31 additions & 29 deletions docs/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { performance } from 'perf_hooks'
import ddTrace, { tracer, Tracer, TracerOptions, Span, SpanContext, SpanOptions, Scope, User } from '..';
import type { plugins } from '..';
import { opentelemetry } from '..';
import { formats, kinds, priority, tags, types } from '../ext';
import { BINARY, HTTP_HEADERS, LOG, TEXT_MAP } from '../ext/formats';
Expand Down Expand Up @@ -157,64 +158,64 @@ const httpOptions = {
middleware: true
};

const httpServerOptions = {
const httpServerOptions: plugins.HttpServer = {
...httpOptions,
hooks: {
request: (span: Span, req, res) => {}
request: (span?: Span, req?, res?) => {}
}
};

const httpClientOptions = {
const httpClientOptions: plugins.HttpClient = {
...httpOptions,
splitByDomain: true,
propagationBlocklist: ['url', /url/, url => true],
hooks: {
request: (span: Span, req, res) => {}
request: (span?: Span, req?, res?) => { }
}
};

const http2ServerOptions = {
const http2ServerOptions: plugins.Http2Server = {
...httpOptions
};

const http2ClientOptions = {
const http2ClientOptions: plugins.Http2Client = {
...httpOptions,
splitByDomain: true
};

const nextOptions = {
const nextOptions: plugins.next = {
service: 'test',
hooks: {
request: (span: Span, params) => { },
request: (span?: Span, params?) => { },
},
};

const graphqlOptions = {
const graphqlOptions: plugins.graphql = {
service: 'test',
depth: 2,
source: true,
variables: ({ foo, baz }) => ({ foo }),
collapse: false,
signature: false,
hooks: {
execute: (span: Span, args, res) => {},
validate: (span: Span, document, errors) => {},
parse: (span: Span, source, document) => {}
execute: (span?: Span, args?, res?) => {},
validate: (span?: Span, document?, errors?) => {},
parse: (span?: Span, source?, document?) => {}
}
};

const elasticsearchOptions = {
const elasticsearchOptions: plugins.elasticsearch = {
service: 'test',
hooks: {
query: (span: Span, params) => {},
query: (span?: Span, params?) => {},
},
};

const awsSdkOptions = {
const awsSdkOptions: plugins.aws_sdk = {
service: 'test',
splitByAwsService: false,
hooks: {
request: (span: Span, response) => {},
request: (span?: Span, response?) => {},
},
s3: false,
sqs: {
Expand All @@ -223,33 +224,32 @@ const awsSdkOptions = {
}
};

const redisOptions = {
const redisOptions: plugins.redis = {
service: 'test',
allowlist: ['info', /auth/i, command => true],
blocklist: ['info', /auth/i, command => true],
};

const sharedbOptions = {
const sharedbOptions: plugins.sharedb = {
service: 'test',
hooks: {
receive: (span: Span, request) => {},
reply: (span: Span, request, reply) => {},
receive: (span?: Span, request?) => {},
reply: (span?: Span, request?, reply?) => {},
},
};

const moleculerOptions = {
const moleculerOptions: plugins.moleculer = {
service: 'test',
client: false,
params: true,
server: {
meta: true
}
};

const openSearchOptions = {
const openSearchOptions: plugins.opensearch = {
service: 'test',
hooks: {
query: (span: Span, params) => {},
query: (span?: Span, params?) => {},
},
};

Expand Down Expand Up @@ -356,8 +356,9 @@ tracer.use('express', { measured: true });

span = tracer.startSpan('test');
span = tracer.startSpan('test', {});
span = tracer.startSpan('test', { childOf: span });
span = tracer.startSpan('test', {
childOf: span || span.context(),
childOf: span.context(),
references: [],
startTime: 123456789.1234,
tags: {
Expand All @@ -371,7 +372,7 @@ tracer.trace('test', { service: 'foo', resource: 'bar', type: 'baz' }, () => {})
tracer.trace('test', { measured: true }, () => {})
tracer.trace('test', (span: Span) => {})
tracer.trace('test', (span: Span, fn: () => void) => {})
tracer.trace('test', (span: Span, fn: (err: Error) => string) => {})
tracer.trace('test', (span: Span, fn: (err: Error) => void) => {})
Qard marked this conversation as resolved.
Show resolved Hide resolved

promise = tracer.trace('test', () => Promise.resolve())

Expand All @@ -382,16 +383,17 @@ promise = tracer.wrap('test', () => Promise.resolve())()

const carrier = {}

tracer.inject(span || span.context(), HTTP_HEADERS, carrier);
context = tracer.extract(HTTP_HEADERS, carrier);
tracer.inject(span, HTTP_HEADERS, carrier);
tracer.inject(span.context(), HTTP_HEADERS, carrier);
context = tracer.extract(HTTP_HEADERS, carrier)!;

traceId = context.toTraceId();
spanId = context.toSpanId();
traceparent = context.toTraceparent();

const scope = tracer.scope()

span = scope.active();
span = scope.active()!;

const activateStringType: string = scope.activate(span, () => 'test');
const activateVoidType: void = scope.activate(span, () => {});
Expand Down
13 changes: 8 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export declare interface Tracer extends opentracing.Tracer {
* unless there is already an active span or `childOf` option. Note that this
* option is deprecated and has been removed in version 4.0.
*/
trace<T> (name: string, fn: (span?: Span, fn?: (error?: Error) => any) => T): T;
trace<T> (name: string, options: TraceOptions & SpanOptions, fn: (span?: Span, done?: (error?: Error) => string) => T): T;
trace<T> (name: string, fn: (span: Span) => T): T;
trace<T> (name: string, fn: (span: Span, done: (error?: Error) => void) => T): T;
trace<T> (name: string, options: TraceOptions & SpanOptions, fn: (span?: Span, done?: (error?: Error) => void) => T): T;

/**
* Wrap a function to automatically create a span activated on its
Expand Down Expand Up @@ -883,7 +884,7 @@ interface Analyzable {
measured?: boolean | { [key: string]: boolean };
}

declare namespace plugins {
export declare namespace plugins {
/** @hidden */
interface Integration {
/**
Expand Down Expand Up @@ -1380,7 +1381,8 @@ declare namespace plugins {
*/
interface ioredis extends Instrumentation {
/**
* List of commands that should be instrumented.
* List of commands that should be instrumented. Commands must be in
* lowercase for example 'xread'.
*
* @default /^.*$/
*/
Expand All @@ -1396,7 +1398,8 @@ declare namespace plugins {

/**
* List of commands that should not be instrumented. Takes precedence over
* allowlist if a command matches an entry in both.
* allowlist if a command matches an entry in both. Commands must be in
* lowercase for example 'xread'.
*
* @default []
*/
Expand Down
Loading