CLOVER馃崁

That was when it all began.

Node.js銇penTelemetry銇儓銉兗銈广倰瑭︺仚

銇撱倢銇併仾銇倰銇椼仧銇忋仸鏇搞亜銇熴倐銇紵

鍓嶃伀Java銇penTelemetry銇儓銉兗銈广倰瑭︺仐銇︺伩銇俱仐銇熴

https://kazuhira-r.hatenablog.com/entry/2022/02/11/005344

OpenTelemetry銇叄銈屻仸銇勩亶銇熴亜銇仺鎬濄亞銇仹銇欍亴銆佷粬銇█瑾炪仹銈傝│銇椼仸銇裤倛銇嗐亱銇仺銇勩亞銇撱仺銇с

浠婂洖銇疦ode.js銇ц│銇椼仸銇裤倠銇撱仺銇仐銇俱仐銇熴

OpenTelemetry

OpenTelemetry銇甒eb銈点偆銉堛伅銇撱仭銈夈

OpenTelemetry

OpenTelemetry銇儎銉笺儷銆APISDK銇偝銉偗銈枫儳銉炽仹銇傘倞銆銉嗐儸銉°儓銉兗銉囥兗銈匡紙銉°儓銉偗銈广併儹銈般併儓銉兗銈癸級銈
瑷堟脯銆佺敓鎴愩佸弾闆嗐亰銈堛伋銈ㄣ偗銈广儩銉笺儓銇椼仸銆併偨銉曘儓銈︺偋銈€伄銉戙儠銈┿兗銉炪兂銈广仺鍕曚綔銇垎鏋愩伀褰圭珛銇︺倠銈傘伄銇ㄣ仌銈屻仸銇勩伨銇欍

OpenTelemetry is a collection of APIs, SDKs, and tools. Use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) to help you analyze your software鈥檚 performance and behavior.

銉夈偔銉ャ儭銉炽儓銇亾銇°倝銆

Documentation | OpenTelemetry

銈炽兂銈汇儣銉堛倓妲嬫垚瑕佺礌銆併儑銉笺偪銈姐兗銈广伀銇ゃ亜銇︺伅銆併亾銇°倝銇1搴︽浉銇嶃伨銇椼仧銆

OpenTelemetry/Jaeger/JAX-RS/MySQLで、Distributed Tracing - CLOVER🍀

銉夈偔銉ャ儭銉炽儓銇搞伄鍙傜収銈傝級銇涖仸銇娿亶銇俱仐銈囥亞銆

OpenTelemetry Concepts | OpenTelemetry

Components | OpenTelemetry

Signals | OpenTelemetry

瑷瑾炪仈銇ㄣ伄instrumentation銈掕銇︺亜銇嶃伨銇欍

Instrumentation | OpenTelemetry

鐝炬檪鐐广仹銆併儓銉兗銈广併儭銉堛儶銈偣銆併儹銈般亴銇欍伖銇table銇伄銇JavaC#锛.NET銇犮亼銇倛銇嗐仹銇欍伃銆

浠婂洖銇JavaScript锛圢ode.js锛夈仹銉堛儸銉笺偣銈掍娇銇嗐亾銇ㄣ伀銇椼伨銇椼倗銇嗐

OpenTelemetry JavaScript Instrumentation

JavaScript銇甶nstrumentation銇儔銈儱銉°兂銉堛伅銇撱仭銈夈

JavaScript | OpenTelemetry

Getting Started銈掕銈嬨仺銆JavaScript銇疦ode.js銇ㄣ儢銉┿偊銈躲伄2绋銇祫銇胯炯銇挎柟銇屻亗銈嬨亾銇ㄣ亴銈忋亱銈娿伨銇欍

Getting Started | OpenTelemetry

Node.js銇柟銇丒xpress銇祫銇胯炯銈渚嬨亴鏇搞亱銈屻仸銇勩伨銇欍

Node.js | OpenTelemetry

銉栥儵銈︺偠鍚戙亼銇柟銇佸疅楱撶殑銇嬨仱浠曟銈傘伝銇兼焙銇俱仯銇︺亜銇亜銈堛亞銇с仚銆

Client instrumentation for the browser is experimental and mostly unspecified

Browser | OpenTelemetry

銈€儣銉偙銉笺偡銉с兂銇祫銇胯炯銈銇伅銆乮nstrumentation銉┿偆銉栥儵銉兗銈掍娇銇c仸鑷嫊鐨勩伀绲勩伩杈笺個銇嬨佽█瑾炪仈銇ㄣ伄SdK銈掍娇銇c仸鎵嬪嫊銇х祫銇胯炯銈
2銇ゃ伄鏂规硶銇屻亗銈娿伨銇欍

Automatic Instrumentation | OpenTelemetry

Manual | OpenTelemetry

浠婂洖銇乮nstrumentation銉┿偆銉栥儵銉兗銈掕銇︺亜銇嶃伨銇欍

Express绛夈伄銉曘儸銉笺儬銉兗銈銆併儵銈ゃ儢銉┿儶銉笺伀瀵惧繙銇椼仧instrumentation銉┿偆銉栥儵銉兗銇屻亗銈嬨伄銇с仚銇屻乤uto-instrumentations-node銇ㄣ亜銇
銉°偪銉戙儍銈便兗銈搞倰浣裤亞銇撱仺銇с仚銇广仸銇甶nstrumentation銉┿偆銉栥儵銉兗銈掔祫銇胯炯銈銇撱仺銇屻仹銇嶃伨銇欍

Note, that using those metapackages increases your dependency graph size. Use individual instrumentation packages if you know exactly which ones you need.

Using instrumentation libraries | OpenTelemetry

銇欍伖銇︺伄insutrumentation銉┿偆銉栥儵銉兗銇岀祫銇胯炯銇俱倢銈嬨仺銇勩亞銇撱仺銇佸綋鐒躲儮銈搞儱銉笺儷銇偟銈ゃ偤銇屽ぇ銇嶃亸銇倞銇俱仚銆傘仢銈屻亴鍟忛銇仾銈嬪牬鍚堛伅銆
鍊嬨呫伄instrumentation銉┿偆銉栥儵銉兗銈掔祫銇胯炯銇裤伨銇欍

浠婂洖銇痑uto-instrumentations-node銈掍娇銇嗐亾銇ㄣ伀銇椼伨銇欍

instrumentation銉┿偆銉栥儵銉兗鑷綋銇仼銇撱伀銇傘倠銇嬨仺銇勩亞銇ㄣ併亾銇°倝銇с仚銆

GitHub - open-telemetry/opentelemetry-js-contrib: OpenTelemetry instrumentation for JavaScript modules

auto-instrumentations-node銇亾銇°倝銆

https://github.com/open-telemetry/opentelemetry-js-contrib/tree/auto-instrumentations-node-v0.39.2/metapackages/auto-instrumentations-node

銈点儩銉笺儓銇曘倢銇︺亜銈銉曘儸銉笺儬銉兗銈銈勩儵銈ゃ儢銉┿儶銉笺伅銆佷互涓嬨伀銉偣銉堛偄銉冦儣銇曘倢銇︺亜銇俱仚銆

OpenTelemetry Meta Packages for Node

鍚刬nstrumentation銉┿偆銉栥儵銉兗銇佷互涓嬨伀銇傘倞銇俱仚銆

https://github.com/open-telemetry/opentelemetry-js-contrib/tree/auto-instrumentations-node-v0.39.2/plugins/node

https://github.com/open-telemetry/opentelemetry-js/tree/experimental/v0.41.2/experimental/packages

銈点兂銉椼儷銇亾銇°倝銆

https://github.com/open-telemetry/opentelemetry-js-contrib/tree/auto-instrumentations-node-v0.39.2/examples

銇俱仧銆併亾銇°倝銇ф绱€仚銈嬨亾銇ㄣ倐銇с亶銇俱仚銆

Registry | OpenTelemetry

銇婇

浠婂洖銇丯ode.js銇≧edis銈掍娇銇c仸浠ヤ笅銇鎴愩伄銈€儣銉偙銉笺偡銉с兂銈掍綔銇c仸銇裤伨銇欍

api-a [Node.js锛廍xpress - axios] 鈫 api-b [Node.js锛廍xpress - ioredis] 鈫 Redis

銈€儣銉偙銉笺偡銉с兂銈2銇ょ敤鎰忋仚銈嬨亾銇ㄣ伀銇倞銇俱仚銇傘亾銈屻倝銇玁ode.js銇甶nstrumentation銉┿偆銉栥儵銉兗銈掔祫銇胯炯銇裤伨銇欍

涓鏂广仹銆銉嗐儸銉°儓銉兗銉囥兗銈裤伄娴併倢銇互涓嬨伀銇倠銈堛亞銇仐銇俱仚銆

OpenTelemetry Collector Agent [api-a銆乤pi-b] 鈫 OpenTelemetry Collector 鈫 Jaeger

OpenTelemetry銇偍銉笺偢銈с兂銉堬紙Node.js銈€儣銉偙銉笺偡銉с兂锛夈亴OpenTelemetry Collector銇儑銉笺偪銈掗併倞銆丱penTelemetry Collector銇嬨倝
Jaeger銇儑銉笺偪銈掋偍銈偣銉濄兗銉堛仐銇俱仚銆

鐠板

浠婂洖銇挵澧冦伅銆併亾銇°倝銆Ubuntu Linux 22.04 LTS銇с仚銆

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy


$ uname -srvmpio
Linux 5.15.0-83-generic #92-Ubuntu SMP Mon Aug 14 09:30:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Node.js銇儛銉笺偢銉с兂銆

$ node --version
v18.17.1


$ npm --version
9.6.7

Redis銇儛銉笺偢銉с兂銆

$ bin/redis-server --version
Redis server v=7.2.1 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=81a2b5148e5873e4

Redis銇佷互涓嬨伄銈炽優銉炽儔銇ц捣鍕曘仐銇︺亜銈嬨倐銇仺銇椼伨銇欍

$ bin/redis-server --bind '0.0.0.0' --requirepass redispass

鍚勩偟銉笺儛銉笺伄IP銈€儔銉偣銇佷互涓嬨伄銈堛亞銇仾銇c仸銇勩倠銈傘伄銇ㄣ仐銇俱仚銆

  • api-a 鈥 172.17.0.2
  • api-b 鈥 172.17.0.3
  • Redis 鈥 172.17.0.4
  • OpenTelemetry Collector 鈥 172.17.0.4
  • Jaeger 鈥 172.17.0.6

OpenTelemetry Collector銇↗aeger銈掋偆銉炽偣銉堛兗銉仚銈

銇俱仛銇疧penTelemetry Collector銇↗aeger銈掋偆銉炽偣銉堛兗銉仐銇︺亰銇嶃伨銇椼倗銇嗐

OpenTelemetry Collector銇併亾銇°倝銇嬨倝銉銈︺兂銉兗銉夈仐銇俱仚銆

Releases · open-telemetry/opentelemetry-collector-releases · GitHub

$ curl -LO https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.84.0/otelcol-contrib_0.84.0_linux_386.tar.gz
$ tar xf otelcol-contrib_0.84.0_linux_386.tar.gz

瑷畾銉曘偂銈ゃ儷銇併亾銇°倝銇儦銉笺偢銈掕銇︿綔鎴愩

Configuration | OpenTelemetry

銇撱亞銇椼伨銇椼仧銆

otel-collector-config.yaml

receivers:
  otlp:
    protocols:
      http:

processors:
  batch:

exporters:
  logging:
    loglevel: debug
  jaeger:
    endpoint: 172.17.0.6:14250
    tls:
      insecure: true

extensions:
  health_check:
  pprof:
  zpages:

service:
  extensions: [health_check, pprof, zpages]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, jaeger]
#    metrics:
#      receivers: [otlp]
#      processors: [batch]
#      exporters: [otlp]
#    logs:
#      receivers: [otlp]
#      processors: [batch]
#      exporters: [otlp]

浠婂洖銇併儭銉堛儶銈偣銇ㄣ儹銈般伅浣裤亜銇俱仜銈撱

瑷畾銉曘偂銈ゃ儷銇偟銉炽儣銉伅銆併亾銇°倝銇倐銇傘倞銇俱仚銆

https://github.com/open-telemetry/opentelemetry-collector-releases/blob/v0.84.0/configs/otelcol-contrib.yaml

璧峰嫊銆

$ ./otelcol-contrib --config otel-collector-config.yaml

缍氥亜銇︺丣aeger銆傘亾銇°倝銇儉銈︺兂銉兗銉夈仐銇

$ curl -LO https://github.com/jaegertracing/jaeger/releases/download/v1.49.0/jaeger-1.49.0-linux-amd64.tar.gz
$ tar xf jaeger-1.49.0-linux-amd64.tar.gz
$ cd jaeger-1.49.0-linux-amd64

璧峰嫊銇欍倠銇犮亼銇с仚銆

$ ./jaeger-all-in-one

銈€儣銉偙銉笺偡銉с兂銈掍綔鎴愩仚銈

銇с伅銆併偄銉椼儶銈便兗銈枫儳銉炽倰浣滄垚銇椼仸銇勩亶銇俱仐銈囥亞銆

api-a

api-a銇綔鎴愩傘亾銇°倝銇api-b銈扝TTP銇у懠銇冲嚭銇欍偄銉椼儶銈便兗銈枫儳銉炽仹銇欍

Node.js銉椼儹銈搞偋銈儓銇綔鎴愩

$ npm init -y
$ npm i -D typescript
$ npm i -D @types/node@v18
$ npm i -D prettier
$ mkdir src

Express銇偆銉炽偣銉堛兗銉

$ npm i express
$ npm i -D @types/express

Axios銇偆銉炽偣銉堛兗銉

$ npm i axios

銇撱伄鏅傜偣銇緷瀛橀枹淇傘伅銇撱仭銈夈

  "devDependencies": {
    "@types/express": "^4.17.17",
    "@types/node": "^18.17.15",
    "prettier": "^3.0.3",
    "typescript": "^5.2.2"
  },
  "dependencies": {
    "axios": "^1.5.0",
    "express": "^4.18.2"
  },

scripts

  "scripts": {
    "build": "tsc --project .",
    "build:watch": "tsc --project . --watch",
    "format": "prettier --write src"
  },

鍚勭ó瑷畾銉曘偂銈ゃ儷銆

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["esnext"],
    "baseUrl": "./src",
    "outDir": "dist",
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noPropertyAccessFromIndexSignature": true,
    "esModuleInterop": true
  },
  "include": [
    "src"
  ]
}

.prettierrc.json

{
  "singleQuote": true,
  "printWidth": 120
}

銈姐兗銈广偝銉笺儔銇亾銇°倝銇х敤鎰忋

src/index.ts

import axios from 'axios';
import express from 'express';

const app = express();
app.use(express.text());

const anotherApiTarget = '172.17.0.3:5000';

app.get('/:id', async (req, res) => {
  const id = req.params['id'];

  const apiResponse = await axios({
    method: 'get',
    headers: { 'Content-Type': 'text/plain' },
    url: `http://${anotherApiTarget}/${id}`,
  });

  const data = apiResponse.data;

  res.contentType('text/plain');
  res.send(data);
});

app.post('/:id', async (req, res) => {
  const id = req.params['id'];
  const body = req.body;

  const apiResponse = await axios({
    method: 'post',
    headers: { 'Content-Type': 'text/plain' },
    url: `http://${anotherApiTarget}/${id}`,
    data: body,
  });

  const data = apiResponse.data;

  res.contentType('text/plain');
  res.send(data);
});

const port = 3000;

app.listen(port, () => {
  console.log(`[${new Date().toISOString()}] start server[${port}]`);
});

銈€偗銈汇偣銇曘倢銇熷唴瀹广倰銆併仢銇伨銇api-b銇浮銇椼仸鍛笺伋鍑恒仚銇犮亼銇偄銉椼儶銈便兗銈枫儳銉炽仹銇欍

api-b

缍氥亜銇︺api-b銆傘亾銇°倝銇丷edis銇搞偄銈偦銈广仚銈嬨偄銉椼儶銈便兗銈枫儳銉炽仹銇欍

Node.js銉椼儹銈搞偋銈儓銇綔鎴愩

$ npm init -y
$ npm i -D typescript
$ npm i -D @types/node@v18
$ npm i -D prettier
$ mkdir src

Express銇偆銉炽偣銉堛兗銉

$ npm i express
$ npm i -D @types/express

ioredis銇偆銉炽偣銉堛兗銉

$ npm i ioredis

銇撱伄鏅傜偣銇緷瀛橀枹淇傘伅銆併亾銇°倝銆

  "devDependencies": {
    "@types/express": "^4.17.17",
    "@types/node": "^18.17.15",
    "prettier": "^3.0.3",
    "typescript": "^5.2.2"
  },
  "dependencies": {
    "express": "^4.18.2",
    "ioredis": "^5.3.2"
  }

瑷畾銉曘偂銈ゃ儷銇悓銇樸仾銇仹銆佺渷鐣ャ仐銇俱仚銆

銈姐兗銈广偝銉笺儔

src/index.ts

import express from 'express';
import Redis from 'ioredis';

const app = express();
app.use(express.text());

const redis = new Redis({
  host: '172.17.0.4',
  port: 6379,
  password: 'redispass',
  db: 0,
});

app.get('/:id', async (req, res) => {
  const id = req.params['id'];

  const data = await redis.get(id);

  res.contentType('text/plain');
  res.send(data);
});

app.post('/:id', async (req, res) => {
  const id = req.params['id'];
  const body = req.body;

  await redis.set(id, body);

  res.contentType('text/plain');
  res.send(body);
});

const port = 5000;

app.listen(port, () => {
  console.log(`[${new Date().toISOString()}] start server[${port}]`);
});

Redis銇setget銇欍倠銇犮亼銇偄銉椼儶銈便兗銈枫儳銉炽仹銇欍

鍕曚綔纰鸿獚

浣滄垚銇椼仧銈€儣銉偙銉笺偡銉с兂銇嫊浣滅⒑瑾嶃倰琛屻亜銇俱仚銆

銇濄倢銇炪倢銉撱儷銉夈仐銇﹁捣鍕曘

## api-a
$ npm run build
$ node dist/index.js
[2023-09-10T13:11:44.215Z] start server[3000]


## api-b
$ npm run build
$ node dist/index.js
[2023-09-10T13:11:51.740Z] start server[5000]

纰鸿獚銆

## 1銈汇儍銉堢洰
$ curl -XPOST -H 'Content-Type: text/plain' 172.17.0.2:3000/foo -d 'Hello World'
Hello World

$ curl 172.17.0.2:3000/foo
Hello World


## 2銈汇儍銉堢洰
$ curl -XPOST -H 'Content-Type: text/plain' 172.17.0.2:3000/bar -d 'Hello OpenTelemetry'
Hello OpenTelemetry

$ curl 172.17.0.2:3000/bar
Hello OpenTelemetry

OK銇с仚銇

銇撱亾銇с偄銉椼儶銈便兗銈枫儳銉炽倰1搴︾祩浜嗐仐銇︺亰銇嶃伨銇欍

OpenTelemetry銇甶nstrumentation銉┿偆銉栥儵銉兗銈掕拷鍔犮仐銇︺併儓銉兗銈枫兂銈般倰琛屻亞

銇濄倢銇с伅銆併偄銉椼儶銈便兗銈枫儳銉炽伀OpenTelemetry銇甶nstrumentation銉┿偆銉栥儵銉兗銈掕拷鍔犮仐銇俱仐銈囥亞銆

Automatic Instrumentation | OpenTelemetry

2銇ゃ伄銈€儣銉偙銉笺偡銉с兂銇併仢銈屻仦銈屼互涓嬨伄渚濆瓨闁總銈掕拷鍔犮仐銇俱仚銆

$ npm i @opentelemetry/api
$ npm i @opentelemetry/auto-instrumentations-node

api-a銇緷瀛橀枹淇傘伅銇撱亞銇倞銇俱仐銇熴

  "dependencies": {
    "@opentelemetry/api": "^1.4.1",
    "@opentelemetry/auto-instrumentations-node": "^0.39.2",
    "axios": "^1.5.0",
    "express": "^4.18.2"
  },
  "devDependencies": {
    "@types/express": "^4.17.17",
    "@types/node": "^18.17.15",
    "prettier": "^3.0.3",
    "typescript": "^5.2.2"
  },

api-b銆

  "devDependencies": {
    "@types/express": "^4.17.17",
    "@types/node": "^18.17.15",
    "prettier": "^3.0.3",
    "typescript": "^5.2.2"
  },
  "dependencies": {
    "@opentelemetry/api": "^1.4.1",
    "@opentelemetry/auto-instrumentations-node": "^0.39.2",
    "express": "^4.18.2",
    "ioredis": "^5.3.2"
  }

娆°伀銆鐠板澶夋暟銈掕ō瀹氥仐銇俱仚銆

Automatic Instrumentation | OpenTelemetry

api-a銆

$ export OTEL_TRACES_EXPORTER=otlp
$ export OTEL_METRICS_EXPORTER=none
$ export OTEL_LOGS_EXPORTER=none
$ export OTEL_EXPORTER_OTLP_ENDPOINT=http://172.17.0.5:4318
$ export OTEL_NODE_RESOURCE_DETECTORS='env,host,os,process,container'
$ export OTEL_SERVICE_NAME=api-a
$ export NODE_OPTIONS='-r @opentelemetry/auto-instrumentations-node/register'

api-b銆

$ export OTEL_TRACES_EXPORTER=otlp
$ export OTEL_METRICS_EXPORTER=none
$ export OTEL_LOGS_EXPORTER=none
$ export OTEL_EXPORTER_OTLP_ENDPOINT=http://172.17.0.5:4318
$ export OTEL_NODE_RESOURCE_DETECTORS='env,host,os,process,container'
$ export OTEL_SERVICE_NAME=api-b
$ export NODE_OPTIONS='-r @opentelemetry/auto-instrumentations-node/register'

銇濄倢銇炪倢銆併儓銉兗銈广伄銈ㄣ偗銈广儩銉笺偪銉煎悕銆丱penTelemetry Collector銇偍銉炽儔銉濄偆銉炽儓銆丯ode.js銇у弾闆嗐仚銈嬨儶銈姐兗銈广併偟銉笺儞銈瑰悕銆
Node.js銇偑銉椼偡銉с兂銈掓寚瀹氥仐銇俱仚銆

OTEL_NODE_RESOURCE_DETECTORS銇寚瀹氥仹銇嶃倠鍊ゃ伅銆併亾銇°倝銇杓夈亴銇傘倞銇俱仚銆傛湁鍔广伀銇欍倠銉偨銉笺偣妞滃嚭姗熻兘銈掓寚瀹氥仐銇俱仚銆

Automatic Instrumentation Configuration | OpenTelemetry

NODE_OPTIONS銇ф寚瀹氥仐銇︺亜銈嬨伄銇-r--require锛夈仹銆乤uto-instrumentations-node銉€偢銉ャ兗銉倰銈€儣銉偙銉笺偡銉с兂銇疅琛屽墠銇
鐧婚尣銇欍倠銈堛亞銇仐銇︺亜銇俱仚銆

$ export NODE_OPTIONS='-r @opentelemetry/auto-instrumentations-node/register'

鎸囧畾銇曘倢銇︺亜銈嬨伄銇併亾銇°倝锛堛亴銉撱儷銉夈仌銈屻仧銈傘伄锛夈仹銇欍伃銆

https://github.com/open-telemetry/opentelemetry-js-contrib/blob/auto-instrumentations-node-v0.39.2/metapackages/auto-instrumentations-node/src/register.ts

銇с伅銆併偄銉椼儶銈便兗銈枫儳銉炽倰銇濄倢銇炪倢璧峰嫊銇椼伨銇欍

api-a銆

$ node dist/index.js
Unable to initialize instrumentation for lambda. Cannot identify lambda handler or task root. { taskRoot: undefined, handlerDef: undefined }
@opentelemetry/instrumentation-grpc Module @grpc/grpc-js has been loaded before @opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring @grpc/grpc-js
OpenTelemetry automatic instrumentation started successfully
[2023-09-10T13:43:42.908Z] start server[3000]

api-b銆

$ node dist/index.js
Unable to initialize instrumentation for lambda. Cannot identify lambda handler or task root. { taskRoot: undefined, handlerDef: undefined }
@opentelemetry/instrumentation-grpc Module @grpc/grpc-js has been loaded before @opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring @grpc/grpc-js
OpenTelemetry automatic instrumentation started successfully
[2023-09-10T13:43:54.530Z] start server[5000]

鍕曚綔纰鸿獚銇椼仧鏅傘伄銈炽優銉炽儔銈掋併倐銇1搴﹀疅琛屻仐銇俱仚銆

## 1銈汇儍銉堢洰
$ curl -XPOST -H 'Content-Type: text/plain' 172.17.0.2:3000/foo -d 'Hello World'
Hello World

$ curl 172.17.0.2:3000/foo
Hello World


## 2銈汇儍銉堢洰
$ curl -XPOST -H 'Content-Type: text/plain' 172.17.0.2:3000/bar -d 'Hello OpenTelemetry'
Hello OpenTelemetry

$ curl 172.17.0.2:3000/bar
Hello OpenTelemetry

銇撱伄鏅傘丱penTelemetry Collector銇儓銉兗銈圭敤銇偍銈偣銉濄兗銈裤兗銇logging銈掓寚瀹氥仐銇︺亜銇熴伄銇

    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, jaeger]

妯欐簴鍑哄姏銇儹銈板嚭鍔涖亴琛屻倧銈屻伨銇欍

2023-09-10T13:44:35.263Z        info    TracesExporter  {"kind": "exporter", "data_type": "traces", "name": "logging", "resource spans": 2, "spans": 274}
2023-09-10T13:44:35.265Z        info    ResourceSpans #0
Resource SchemaURL:
Resource attributes:
     -> service.name: Str(api-a)
     -> telemetry.sdk.language: Str(nodejs)
     -> telemetry.sdk.name: Str(opentelemetry)
     -> telemetry.sdk.version: Str(1.15.2)
     -> host.name: Str(4c6b959a4813)
     -> host.arch: Str(amd64)
     -> os.type: Str(linux)
     -> os.version: Str(5.15.0-83-generic)
     -> process.pid: Int(10)
     -> process.executable.name: Str(node)
     -> process.executable.path: Str(/usr/local/bin/node)
     -> process.command_args: Slice(["/usr/local/bin/node","/host/dist/index.js"])
     -> process.runtime.version: Str(18.17.1)
     -> process.runtime.name: Str(nodejs)
     -> process.runtime.description: Str(Node.js)
     -> process.command: Str(/host/dist/index.js)
     -> process.owner: Str(root)
     -> container.id: Str(4c6b959a48131281774ca882cd48d13f7fa101292c4fdaba1cb6d9512ae8279c)
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope @opentelemetry/instrumentation-express 0.33.1
Span #0
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 659e4db256207700
    Name           : middleware - query
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.073999872 +0000 UTC
    End time       : 2023-09-10 13:44:30.074353408 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/)
     -> express.name: Str(query)
     -> express.type: Str(middleware)
Span #1
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 9badd350a036fedb
    Name           : middleware - expressInit
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.073999872 +0000 UTC
    End time       : 2023-09-10 13:44:30.074142976 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/)
     -> express.name: Str(expressInit)
     -> express.type: Str(middleware)
Span #2
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 187778470bf7ef67
    Name           : middleware - textParser
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.075000064 +0000 UTC
    End time       : 2023-09-10 13:44:30.10999552 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/)
     -> express.name: Str(textParser)
     -> express.type: Str(middleware)
Span #3
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : f800d6e43ecf2450
    Name           : request handler - /:id
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.110000128 +0000 UTC
    End time       : 2023-09-10 13:44:30.110024704 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/:id)
     -> express.name: Str(/:id)
     -> express.type: Str(request_handler)
Span #4
    Trace ID       : 2b18529d370ae8c11365421e84982941
    Parent ID      : 19714ca57cca6501
    ID             : a0f2226e6243c28c
    Name           : middleware - query
    Kind           : Internal
    Start time     : 2023-09-10 13:44:33.296 +0000 UTC
    End time       : 2023-09-10 13:44:33.296233472 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/)
     -> express.name: Str(query)
     -> express.type: Str(middleware)
Span #5
    Trace ID       : 2b18529d370ae8c11365421e84982941
    Parent ID      : 19714ca57cca6501
    ID             : d0d508243bcb9512
    Name           : middleware - expressInit
    Kind           : Internal
    Start time     : 2023-09-10 13:44:33.296 +0000 UTC
    End time       : 2023-09-10 13:44:33.296146432 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/)
     -> express.name: Str(expressInit)
     -> express.type: Str(middleware)
Span #6
    Trace ID       : 2b18529d370ae8c11365421e84982941
    Parent ID      : 19714ca57cca6501
    ID             : bebff8ab7d1d4df0
    Name           : middleware - textParser
    Kind           : Internal
    Start time     : 2023-09-10 13:44:33.296 +0000 UTC
    End time       : 2023-09-10 13:44:33.296095232 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/)
     -> express.name: Str(textParser)
     -> express.type: Str(middleware)
Span #7
    Trace ID       : 2b18529d370ae8c11365421e84982941
    Parent ID      : 19714ca57cca6501
    ID             : 81dc2a843298cd9c
    Name           : request handler - /:id
    Kind           : Internal
    Start time     : 2023-09-10 13:44:33.296999936 +0000 UTC
    End time       : 2023-09-10 13:44:33.297020928 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> http.route: Str(/:id)
     -> express.name: Str(/:id)
     -> express.type: Str(request_handler)
ScopeSpans #1
ScopeSpans SchemaURL:
InstrumentationScope @opentelemetry/instrumentation-fs 0.8.1
Span #0
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 2e2c267b570cece5
    Name           : fs realpathSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.076999936 +0000 UTC
    End time       : 2023-09-10 13:44:30.077081856 +0000 UTC
    Status code    : Unset
    Status message :
Span #1
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 1069e2d2779bd261
    Name           : fs readFileSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.076999936 +0000 UTC
    End time       : 2023-09-10 13:44:30.077584384 +0000 UTC
    Status code    : Unset
    Status message :
Span #2
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 8ff087d01743abde
    Name           : fs realpathSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.078000128 +0000 UTC
    End time       : 2023-09-10 13:44:30.078066944 +0000 UTC
    Status code    : Unset
    Status message :
Span #3
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 35f3875a31231c27
    Name           : fs readFileSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.078000128 +0000 UTC
    End time       : 2023-09-10 13:44:30.078881024 +0000 UTC
    Status code    : Unset
    Status message :
Span #4
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 011b3a0be7bf57af
    Name           : fs realpathSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.079000064 +0000 UTC
    End time       : 2023-09-10 13:44:30.079028992 +0000 UTC
    Status code    : Unset
    Status message :
Span #5
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 5225cd698cb78472
    Name           : fs statSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.08 +0000 UTC
    End time       : 2023-09-10 13:44:30.08004224 +0000 UTC
    Status code    : Unset
    Status message :
Span #6
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : 68189d6d7c681331
    Name           : fs statSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.08 +0000 UTC
    End time       : 2023-09-10 13:44:30.080021248 +0000 UTC
    Status code    : Unset
    Status message :
Span #7
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : dd7e5b922a9b3317
    Name           : fs statSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.08 +0000 UTC
    End time       : 2023-09-10 13:44:30.080056064 +0000 UTC
    Status code    : Unset
    Status message :
Span #8
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : ad91deb4b23e306a
    Name           : fs statSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.08 +0000 UTC
    End time       : 2023-09-10 13:44:30.08002432 +0000 UTC
    Status code    : Unset
    Status message :
Span #9
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : e335fdf9884553b2
    Name           : fs statSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.08 +0000 UTC
    End time       : 2023-09-10 13:44:30.080022272 +0000 UTC
    Status code    : Unset
    Status message :
Span #10
    Trace ID       : af0185f48699f89665530099b3b40b99
    Parent ID      : 37c3410962cabf7d
    ID             : a604af9a0ca97445
    Name           : fs statSync
    Kind           : Internal
    Start time     : 2023-09-10 13:44:30.080999936 +0000 UTC
    End time       : 2023-09-10 13:44:30.081023232 +0000 UTC
    Status code    : Unset
    Status message :

銆滅渷鐣ャ

銇с伅銆丣aeger銇佷俊銇曘倢銇熴儑銉笺偪銈掕銇︺伩銇俱仐銈囥亞銆

http://[Jaeger銇屽嫊浣溿仐銇︺亜銈嬨儧銈广儓]:16686/銇偄銈偦銈广仐銇eb UI銈掕〃绀恒仐銇︺伩銈嬨仺銆2銇ゃ伄銈点兗銉撱偣锛圝aeger鑷韩銈掑惈銈併倠銇3銇わ級銇
瑾嶈瓨銇曘倢銇︺亜銈嬨亾銇ㄣ亴纰鸿獚銇с亶銇俱仚銆

Service銇сapi-a銆嶃倰閬搞倱銇с併孎ind Traces銆嶃儨銈裤兂銈掓娂銇椼仸銇裤伨銇欍

琛ㄧず銇椼仧銇勩儓銉兗銈广儑銉笺偪銈掗伕鎶炪仐銇︺伩銇俱仐銈囥亞銆

api-a: POST /:id銆嶃倰閬告姙銇椼仸銇裤伨銇欍

Span銈掗枊銇勩仸銇裤伨銇欍

Tags銈凱rocess銈傞枊銇戙伨銇欍

Redis銇搞伄銈€偗銈汇偣銈傝閷层仌銈屻仸銇勩伨銇欍伃銆

銇┿伄instrumentation銉┿偆銉栥儵銉兗銇倛銇c仸瑷橀尣銇曘倢銇熴亱銇乀ags銇otel.library.name銈掕銈屻伆銈忋亱銈娿仢銇嗐仹銇欍

浠婂洖銇併仢銈屻仦銈屼互涓嬨仹瑷橀尣銇曘倢銇︺亜銇俱仚銆

鏈寰屻伀銈点兗銉撱偣闁撱伄渚濆瓨闁總銈掕〃绀恒仐銇︺併亰銈忋倞銇仐銇俱仐銈囥亞銆

銇娿倧銈娿伀

Node.js銈掍娇銇c仸銆丱penTelemetry銇с儓銉兗銈广倰銇椼仸銇裤伨銇椼仧銆

Java銇1搴︺倓銇c仸銇勩仧銇仹OpenTelemetry Collactor銇柟銇伨銇犮倛銇嬨仯銇熴仹銇欍亴銆丯ode.js銇甶nstrumentation銉┿偆銉栥儵銉兗銇俱倧銈娿伅銇勩倣銇勩倣
瑾裤伖銇﹀洖銇c仧銇仹銇濄倢銇倞銇嫤鍔淬仐銇俱仐銇熴

銇熴仩瑭︺仐銇︺亜銈嬨仩銇戙仾銇伀銆佸繀瑕佷互涓娿伀杩姐亜銇欍亷銇︺亜銈嬨伄銇с伅銇ㄣ亜銇嗘皸銇屻仐銇亜銇с倐銇亜銇с仚銇屻

Node.js銇т娇銇哋penTelemetry銈傘伨銇犮亜銇忋仱銇嬭│銇椼仸銇裤仧銇勩亾銇ㄣ亴銇傘倠銇仹銇欍亴銆Java銇ㄥ悎銈忋仜銇︺倐銇嗐仭銈囥仯銇ㄦ叄銈屻仸銇勩亸銇ㄣ仐銇俱仐銈囥亞銇嬨