loopbackio / loopbackio/loopback-next

Facing multiple Issues while integrating opentelemetry tracing

Open
#6,791 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

Steps to reproduce

Install the following packages:

@opentelemetry/node
@opentelemetry/tracing
@opentelemetry/exporter-jaeger
@opentelemetry/plugin-http
@opentelemetry/plugin-https
@opentelemetry/plugin-express

AT the top of index.ts

import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
import { NodeTracerProvider } from '@opentelemetry/node';
import { SimpleSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/tracing';

Following at the top of the main function in index.ts file

  const option = {
    serviceName: 'basic-service',
    tags: [], // optional
    // You can use the default UDPSender
    host: 'localhost', // optional
    port: 6832, // optional
    // OR you can use the HTTPSender as follows
    // endpoint: 'http://localhost:14268/api/traces',
  }

  // Configure span processor to send spans to the exporter
  const exporter = new JaegerExporter(option);
  provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
  provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
  provider.register();

Then import the following in the application.ts file:

import openTelemetry, { Span, Tracer } from '@opentelemetry/api';

Then I added this middleware in the application.ts

const middle: Middleware = async (ctx, next) => {
  const trace = openTelemetry.trace.getTracer('loopback:tracer');
  let span: Span;
  span = trace.startSpan(ctx.request.url);
  span.setAttribute('key', 'value');
  span.addEvent('invoking next');
  const res = await next();
  return res;
}

Then bind this middleware in the constructor in the application.ts:

this.middleware(middle);

Another thing if I use Axios to make an HTTP request then context propagation happens properly but if I use the recommended way of loopback by creating a rest connector then it doesn't happen. I have installed all the required modules in the app.

Current Behavior

Some modules (redis, express) were already required when their respective plugin was loaded, some plugins might not work. Make sure the SDK is setup before you require in other modules.

Expected Behavior

As per the auto instrument libraries from opentelemetry for HTTP, express, redis, psotgres all opentelemetry modules required to be loaded before any of such application module are loaded. So as per code sample above it should have worked all fine.

Another thing if I use Axios to make an HTTP request then context propagation happens properly but if I use the recommended way of loopback by creating a rest connector then it doesn't happen. I have installed all the required modules in the app.

Additional information

linux x64 12.18.4
├── UNMET PEER DEPENDENCY @loopback/boot@2.0.1
├── UNMET PEER DEPENDENCY @loopback/context@3.1.0
├── UNMET PEER DEPENDENCY @loopback/core@2.1.0
├── @loopback/metadata@2.0.4
├── @loopback/openapi-v3@3.1.0
├── UNMET PEER DEPENDENCY @loopback/repository@2.0.2
├── @loopback/repository-json-schema@2.0.2
├── UNMET PEER DEPENDENCY @loopback/rest@3.0.1
├── @loopback/rest-explorer@2.0.1
├── @loopback/service-proxy@2.0.1
├── loopback-connector-kv-redis@3.0.3
├── loopback-connector-postgresql@3.9.1
├── loopback-datasource-juggler@4.19.2
├── loopback4-authentication@2.1.4
├── loopback4-authorization@2.3.2
├── loopback4-helmet@1.0.3
├─┬ UNMET DEPENDENCY loopback4-ratelimiter@1.0.0
│ ├── @loopback/boot@1.7.4
│ ├── @loopback/context@2.1.1
│ ├── @loopback/core@1.12.4
│ ├── @loopback/repository@2.6.0
│ ├── @loopback/rest@3.3.2
│ ├── loopback-connector-kv-redis@3.0.3 deduped
├── loopback4-soft-delete@1.2.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the setup shown in index.ts and the middleware and rest-connector usage in application.ts. Reproduce the OpenTelemetry configuration, compare Axios propagation with the recommended LoopBack rest connector, and check the listed package versions and peer-dependency warnings. Done means the intended LoopBack request path propagates tracing consistently with the documented setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, node.js, postgresql, redis, typescript
Domain
backend-api-design, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.