Skip to content

Manual Instrumentation for gRPC for TypeScript #13504

Open
@sdzhong

Description

@sdzhong

SDK

JavaScript SDK

Description

https://docs.sentry.io/platforms/javascript/guides/nestjs/tracing/distributed-tracing/custom-instrumentation/#server-side-propagation

The example snippet is for JavaScript which isn't entirely accurate for TypeScript. Using TypeScript shows these problems

  1. The type of nextCall is BaseServerInterceptingCall which has a private Metadata property. If you type nextCall as that, you cannot access metadata due to that classifier. While its not real private (which exists in JS now but isnt being used here) you can still access it at runtime no problem, but if you use TypeScript to type that properly, you will fail the compiler check.
  2. The methodDescriptor shape is the following which does not contain the service property that this snippet attempts to use for the grpc.service property.
{
  path: string,
  requestStream: boolean,
  responseStream: boolean,
  requestDeserialize: Function,
  responseSerialize: Function
}
  1. The span.setStatus({ code: "error" }) line fails the typecheck because Sentry's SDK types are actually looking for one of these and not a string.
declare const SPAN_STATUS_UNSET = 0;
declare const SPAN_STATUS_OK = 1;
declare const SPAN_STATUS_ERROR = 2;
/** The status code of a span. */
export type SpanStatusCode = typeof SPAN_STATUS_UNSET | typeof SPAN_STATUS_OK | typeof SPAN_STATUS_ERROR;

Suggested Solution

Provide an example snippet for TypeScript.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions