diff --git a/packages/opentelemetry-browser-extension-autoinjection/package.json b/packages/opentelemetry-browser-extension-autoinjection/package.json index d8129b60a4..2238d80d1e 100644 --- a/packages/opentelemetry-browser-extension-autoinjection/package.json +++ b/packages/opentelemetry-browser-extension-autoinjection/package.json @@ -68,12 +68,12 @@ "@material-ui/lab": "4.0.0-alpha.60", "@opentelemetry/context-zone": "1.0.1", "@opentelemetry/core": "1.0.1", - "@opentelemetry/exporter-otlp-http": "0.26.0", + "@opentelemetry/exporter-trace-otlp-http": "0.27.0", "@opentelemetry/exporter-zipkin": "1.0.1", "@opentelemetry/instrumentation": "0.27.0", - "@opentelemetry/instrumentation-document-load": "^0.27.0", - "@opentelemetry/instrumentation-fetch": "0.26.0", - "@opentelemetry/instrumentation-xml-http-request": "0.26.0", + "@opentelemetry/instrumentation-document-load": "0.27.0", + "@opentelemetry/instrumentation-fetch": "0.27.0", + "@opentelemetry/instrumentation-xml-http-request": "0.27.0", "@opentelemetry/resources": "1.0.1", "@opentelemetry/sdk-trace-base": "1.0.1", "@opentelemetry/sdk-trace-web": "1.0.1", diff --git a/packages/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts b/packages/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts index 997143f630..d467460e7d 100644 --- a/packages/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts +++ b/packages/opentelemetry-browser-extension-autoinjection/src/instrumentation/WebInstrumentation.ts @@ -20,7 +20,7 @@ import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xm import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; import { ZoneContextManager } from '@opentelemetry/context-zone'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; -import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-http'; +import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; import { BatchSpanProcessor, ConsoleSpanExporter, diff --git a/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts index 985238a0b4..cfe666c559 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts @@ -87,7 +87,7 @@ export class FastifyInstrumentation extends InstrumentationBase { const routeName = request.routerPath; if (routeName && rpcMetadata?.type === RPCType.HTTP) { rpcMetadata.span.setAttribute(SemanticAttributes.HTTP_ROUTE, routeName); - rpcMetadata.span.updateName(`${request.method} ${routeName || '/'}`); + rpcMetadata.span.updateName(`${request.method} ${routeName}`); } done(); }; @@ -96,11 +96,11 @@ export class FastifyInstrumentation extends InstrumentationBase { private _wrapHandler( pluginName: string, hookName: string, - original: (...args: unknown[]) => Promise | void, + original: (...args: unknown[]) => Promise, syncFunctionWithDone: boolean - ): () => Promise | void { + ): () => Promise { const instrumentation = this; - return function (this: any, ...args: unknown[]): Promise | void { + return function (this: any, ...args: unknown[]): Promise { if (!instrumentation.isEnabled()) { return original.apply(this, args); } @@ -135,7 +135,7 @@ export class FastifyInstrumentation extends InstrumentationBase { return original.apply(this, args); }, err => { - if (err) { + if (err instanceof Error) { span.setStatus({ code: SpanStatusCode.ERROR, message: err.message, diff --git a/plugins/node/opentelemetry-instrumentation-fastify/src/utils.ts b/plugins/node/opentelemetry-instrumentation-fastify/src/utils.ts index 7b328fea3c..45efc3ab75 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-fastify/src/utils.ts @@ -88,36 +88,35 @@ export function endSpan(reply: PluginFastifyReply, err?: any) { * function fails */ export function safeExecuteInTheMiddleMaybePromise( - execute: () => Promise | T, - onFinish: (e: Error | undefined, result?: T) => void, + execute: () => Promise, + onFinish: (e: unknown, result?: T) => void, preventThrowingError?: boolean -): Promise | T | void { - let error: Error | undefined; - let executeResult: Promise | T | void; - let isPromise = false; - let result: T | undefined = undefined; +): Promise; +export function safeExecuteInTheMiddleMaybePromise( + execute: () => T, + onFinish: (e: unknown, result?: T) => void, + preventThrowingError?: boolean +): T; +export function safeExecuteInTheMiddleMaybePromise( + execute: () => T | Promise, + onFinish: (e: unknown, result?: T) => void, + preventThrowingError?: boolean +): T | Promise | undefined { + let error: unknown; + let result: T | Promise | undefined = undefined; try { - executeResult = execute(); - const promiseResult = executeResult as Promise; + result = execute(); - isPromise = promiseResult && typeof promiseResult.then === 'function'; - - if (isPromise) { - promiseResult.then( - res => { - onFinish(undefined, res); - }, - (err: Error) => { - onFinish(err); - } + if (isPromise(result)) { + result.then( + res => onFinish(undefined, res), + err => onFinish(err) ); - } else { - result = executeResult as T | undefined; } } catch (e) { error = e; } finally { - if (!isPromise) { + if (!isPromise(result)) { onFinish(error, result); if (error && !preventThrowingError) { // eslint-disable-next-line no-unsafe-finally @@ -125,6 +124,16 @@ export function safeExecuteInTheMiddleMaybePromise( } } // eslint-disable-next-line no-unsafe-finally - return executeResult; + return result; } } + +function isPromise(val: T | Promise): val is Promise { + return ( + (typeof val === 'object' && + val && + typeof Object.getOwnPropertyDescriptor(val, 'then')?.value === + 'function') || + false + ); +}