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: fastify and browser autoinjection failed to compile #793

Merged
merged 5 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
"@opentelemetry/exporter-otlp-http": "0.26.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be also outdated

"@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand All @@ -96,11 +96,11 @@ export class FastifyInstrumentation extends InstrumentationBase {
private _wrapHandler(
pluginName: string,
hookName: string,
original: (...args: unknown[]) => Promise<any> | void,
original: (...args: unknown[]) => Promise<unknown>,
syncFunctionWithDone: boolean
): () => Promise<any> | void {
): () => Promise<unknown> {
const instrumentation = this;
return function (this: any, ...args: unknown[]): Promise<any> | void {
return function (this: any, ...args: unknown[]): Promise<unknown> {
if (!instrumentation.isEnabled()) {
return original.apply(this, args);
}
Expand Down Expand Up @@ -129,26 +129,28 @@ export class FastifyInstrumentation extends InstrumentationBase {
};
}

return context.with(trace.setSpan(context.active(), span), () => {
return safeExecuteInTheMiddleMaybePromise(
() => {
return original.apply(this, args);
},
err => {
if (err) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: err.message,
});
span.recordException(err);
return Promise.resolve(
context.with(trace.setSpan(context.active(), span), () => {
return safeExecuteInTheMiddleMaybePromise(
() => {
return original.apply(this, args);
},
err => {
if (err) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: err.message,
});
span.recordException(err);
}
// async hooks should end the span as soon as the promise is resolved
if (!syncFunctionWithDone) {
endSpan(reply);
}
}
// async hooks should end the span as soon as the promise is resolved
if (!syncFunctionWithDone) {
endSpan(reply);
}
}
);
});
);
})
);
};
}

Expand Down