Skip to content

Commit

Permalink
Fix other TypeScript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Belanger committed Jan 2, 2024
1 parent d9edad8 commit 587f63f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
58 changes: 30 additions & 28 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 @@ -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
8 changes: 5 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ interface Analyzable {
measured?: boolean | { [key: string]: boolean };
}

declare namespace plugins {
export declare namespace plugins {
/** @hidden */
interface Integration {
/**
Expand Down Expand Up @@ -1381,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 @@ -1397,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

0 comments on commit 587f63f

Please sign in to comment.