loopbackio / loopbackio/loopback-next

Facing multiple Issues while integrating opentelemetry tracing

Ouverte
#6,791 15 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
TypeScript
Étoiles
5.1k
Forks
1.1k
Merge moyen
2 j 21 h
PR mergées (30 j)
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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la configuration présentée dans index.ts ainsi que par l’utilisation de middleware et de rest-connector dans application.ts. Reproduisez la configuration OpenTelemetry, comparez la propagation avec Axios à celle du connecteur rest recommandé de LoopBack, et vérifiez les versions de packages indiquées ainsi que les avertissements de dépendances peer. Le travail est terminé lorsque le chemin de requête LoopBack prévu propage le tracing de manière cohérente avec la configuration documentée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
express, node.js, postgresql, redis, typescript
Domaine
backend-api-design, observability
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.