diff --git a/content/ja/docs/languages/js/_index.md b/content/ja/docs/languages/js/_index.md index 903a4fbf1ac7..8abd37ba9a12 100644 --- a/content/ja/docs/languages/js/_index.md +++ b/content/ja/docs/languages/js/_index.md @@ -5,8 +5,7 @@ description: >- alt="JavaScript"> JavaScript(Node.jsとブラウザ向け)でのOpenTelemetryの言語固有実装。 aliases: [/js, /js/metrics, /js/tracing] weight: 20 -default_lang_commit: 6f3712c5cda4ea79f75fb410521880396ca30c91 -drifted_from_default: true +default_lang_commit: 276d7eb3f936deef6487cdd2b1d89822951da6c8 --- {{% docs/languages/index-intro js /%}} diff --git a/content/ja/docs/languages/js/getting-started/nodejs.md b/content/ja/docs/languages/js/getting-started/nodejs.md index 4e484cab04ed..3a8d1ee4c087 100644 --- a/content/ja/docs/languages/js/getting-started/nodejs.md +++ b/content/ja/docs/languages/js/getting-started/nodejs.md @@ -3,9 +3,8 @@ title: Node.js description: 5分未満でアプリのテレメトリーを取得しましょう! aliases: [/docs/js/getting_started/nodejs] weight: 10 -default_lang_commit: 6f3712c5cda4ea79f75fb410521880396ca30c91 -drifted_from_default: true -cSpell:ignore: autoinstrumentations KHTML rolldice +default_lang_commit: 276d7eb3f936deef6487cdd2b1d89822951da6c8 +cSpell:ignore: autoinstrumentations rolldice --- このページでは、Node.jsでOpenTelemetryを開始する方法を説明します。 @@ -48,14 +47,8 @@ npm init -y {{< tabpane text=true >}} {{% tab TypeScript %}} ```sh -npm install typescript \ - ts-node \ - @types/node \ - express \ - @types/express - -# TypeScriptを初期化 -npx tsc --init +npm install express @types/express +npm install -D tsx # TypeScript (.ts)ファイルをnodeで直接実行するためのツール ``` {{% /tab %}} {{% tab JavaScript %}} @@ -121,7 +114,7 @@ app.listen(PORT, () => { {{< tabpane text=true >}} {{% tab TypeScript %}} ```console -$ npx ts-node app.ts +$ npx tsx app.ts Listening for requests on http://localhost:8080 ``` @@ -160,9 +153,14 @@ npm install @opentelemetry/sdk-node \ ### セットアップ {#setup} 計装のセットアップと構成は、アプリケーションコードの _前に_ 実行する必要があります。 -このタスクによく使用されるツールの1つは、[--require](https://nodejs.org/api/cli.html#-r---require-module)フラグです。 +このタスクによく使用されるツールの1つは、[--import](https://nodejs.org/api/cli.html#--importmodule)フラグです。 -計装セットアップコードを含む`instrumentation.ts`(TypeScriptを使用しない場合は`instrumentation.js`)という名前のファイルを作成します。 +計装セットアップコードを含む`instrumentation.ts`(TypeScriptを使用しない場合は`instrumentation.mjs`)という名前のファイルを作成します。 + +{{% alert title="注意" %}} +以下の`--import instrumentation.ts`(TypeScript)を使用した例は、Node.js v.20以降が必要です。 +Node.js v.18を使用している場合は、JavaScriptの例を使用してください。 +{{% /alert %}} {{< tabpane text=true >}} {{% tab TypeScript %}} @@ -190,17 +188,14 @@ sdk.start(); {{% /tab %}} {{% tab JavaScript %}} ```js -/*instrumentation.js*/ -// 依存関係をrequire -const { NodeSDK } = require('@opentelemetry/sdk-node'); -const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node'); -const { - getNodeAutoInstrumentations, -} = require('@opentelemetry/auto-instrumentations-node'); -const { +/*instrumentation.mjs*/ +import { NodeSDK } from '@opentelemetry/sdk-node'; +import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node'; +import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; +import { PeriodicExportingMetricReader, ConsoleMetricExporter, -} = require('@opentelemetry/sdk-metrics'); +} from '@opentelemetry/sdk-metrics'; const sdk = new NodeSDK({ traceExporter: new ConsoleSpanExporter(), @@ -217,20 +212,20 @@ sdk.start(); ## 計装されたアプリを実行 {#run-the-instrumented-app} -これで、通常どおりアプリケーションを実行できますが、`--require`フラグを使用してアプリケーションコードの前に計装をロードできます。 -`NODE_OPTIONS`環境変数に`--require @opentelemetry/auto-instrumentations-node/register`などの競合する`--require`フラグがないことを確認してください。 +これで、通常どおりアプリケーションを実行できますが、`--import`フラグを使用してアプリケーションコードの前に計装をロードできます。 +`NODE_OPTIONS`環境変数に`--require @opentelemetry/auto-instrumentations-node/register`などの競合する`--import`または`--require`フラグがないことを確認してください。 {{< tabpane text=true >}} {{% tab TypeScript %}} ```console -$ npx ts-node --require ./instrumentation.ts app.ts +$ npx tsx --import ./instrumentation.ts app.ts Listening for requests on http://localhost:8080 ``` {{% /tab %}} {{% tab JavaScript %}} ```console -$ node --require ./instrumentation.js app.js +$ node --import ./instrumentation.mjs app.js Listening for requests on http://localhost:8080 ``` @@ -242,82 +237,98 @@ Webブラウザでを開き、ページを数回
出力例を表示 -```json +```js { - "traceId": "3f1fe6256ea46d19ec3ca97b3409ad6d", - "parentId": "f0b7b340dd6e08a7", - "name": "middleware - query", - "id": "41a27f331c7bfed3", - "kind": 0, - "timestamp": 1624982589722992, - "duration": 417, - "attributes": { - "http.route": "/", - "express.name": "query", - "express.type": "middleware" + resource: { + attributes: { + 'host.arch': 'arm64', + 'host.id': '8FEBBC33-D6DA-57FC-8EF0-1A9C14B919F8', + 'process.pid': 12460, + // ... 一部のリソース属性は省略 ... + 'process.runtime.version': '22.17.1', + 'process.runtime.name': 'nodejs', + 'process.runtime.description': 'Node.js', + 'telemetry.sdk.language': 'nodejs', + 'telemetry.sdk.name': 'opentelemetry', + 'telemetry.sdk.version': '2.0.1' + } }, - "status": { "code": 0 }, - "events": [] -} -{ - "traceId": "3f1fe6256ea46d19ec3ca97b3409ad6d", - "parentId": "f0b7b340dd6e08a7", - "name": "middleware - expressInit", - "id": "e0ed537a699f652a", - "kind": 0, - "timestamp": 1624982589725778, - "duration": 673, - "attributes": { - "http.route": "/", - "express.name": "expressInit", - "express.type": "middleware" + instrumentationScope: { + name: '@opentelemetry/instrumentation-express', + version: '0.52.0', + schemaUrl: undefined }, - "status": { code: 0 }, - "events": [] -} -{ - "traceId": "3f1fe6256ea46d19ec3ca97b3409ad6d", - "parentId": "f0b7b340dd6e08a7", - "name": "request handler - /", - "id": "8614a81e1847b7ef", - "kind": 0, - "timestamp": 1624982589726941, - "duration": 21, - "attributes": { - "http.route": "/", - "express.name": "/", - "express.type": "request_handler" + traceId: '61e8960c349ca2a3a51289e050fd3b82', + parentSpanContext: { + traceId: '61e8960c349ca2a3a51289e050fd3b82', + spanId: '631b666604f933bc', + traceFlags: 1, + traceState: undefined }, - "status": { code: 0 }, - "events": [] + traceState: undefined, + name: 'request handler - /rolldice', + id: 'd8fcc05ac4f60c99', + kind: 0, + timestamp: 1755719307779000, + duration: 2801.5, + attributes: { + 'http.route': '/rolldice', + 'express.name': '/rolldice', + 'express.type': 'request_handler' + }, + status: { code: 0 }, + events: [], + links: [] } { - "traceId": "3f1fe6256ea46d19ec3ca97b3409ad6d", - "parentId": undefined, - "name": "GET /", - "id": "f0b7b340dd6e08a7", - "kind": 1, - "timestamp": 1624982589720260, - "duration": 11380, - "attributes": { - "http.url": "http://localhost:8080/", - "http.host": "localhost:8080", - "net.host.name": "localhost", - "http.method": "GET", - "http.route": "", - "http.target": "/", - "http.user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36", - "http.flavor": "1.1", - "net.transport": "ip_tcp", - "net.host.ip": "::1", - "net.host.port": 8080, - "net.peer.ip": "::1", - "net.peer.port": 61520, - "http.status_code": 304, - "http.status_text": "NOT MODIFIED" + resource: { + attributes: { + 'host.arch': 'arm64', + 'host.id': '8FEBBC33-D6DA-57FC-8EF0-1A9C14B919F8', + 'process.pid': 12460, + // ... 一部のリソース属性は省略 ... + 'process.runtime.version': '22.17.1', + 'process.runtime.name': 'nodejs', + 'process.runtime.description': 'Node.js', + 'telemetry.sdk.language': 'nodejs', + 'telemetry.sdk.name': 'opentelemetry', + 'telemetry.sdk.version': '2.0.1' + } }, - "status": { "code": 1 }, - "events": [] + instrumentationScope: { + name: '@opentelemetry/instrumentation-http', + version: '0.203.0', + schemaUrl: undefined + }, + traceId: '61e8960c349ca2a3a51289e050fd3b82', + parentSpanContext: undefined, + traceState: undefined, + name: 'GET /rolldice', + id: '631b666604f933bc', + kind: 1, + timestamp: 1755719307777000, + duration: 4705.75, + attributes: { + 'http.url': 'http://localhost:8080/rolldice', + 'http.host': 'localhost:8080', + 'net.host.name': 'localhost', + 'http.method': 'GET', + 'http.scheme': 'http', + 'http.target': '/rolldice', + 'http.user_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:141.0) Gecko/20100101 Firefox/141.0', + 'http.flavor': '1.1', + 'net.transport': 'ip_tcp', + 'net.host.ip': '::ffff:127.0.0.1', + 'net.host.port': 8080, + 'net.peer.ip': '::ffff:127.0.0.1', + 'net.peer.port': 63067, + 'http.status_code': 200, + 'http.status_text': 'OK', + 'http.route': '/rolldice' + }, + status: { code: 0 }, + events: [], + links: [] } ``` @@ -331,127 +342,152 @@ Webブラウザでを開き、ページを数回
出力例を表示 -```yaml +```js { descriptor: { name: 'http.server.duration', type: 'HISTOGRAM', - description: 'measures the duration of the inbound HTTP requests', + description: 'Measures the duration of inbound HTTP requests.', unit: 'ms', - valueType: 1 + valueType: 1, + advice: {} }, dataPointType: 0, dataPoints: [ { - attributes: [Object], - startTime: [Array], - endTime: [Array], - value: [Object] + attributes: { + 'http.scheme': 'http', + 'http.method': 'GET', + 'net.host.name': 'localhost', + 'http.flavor': '1.1', + 'http.status_code': 200, + 'net.host.port': 8080, + 'http.route': '/rolldice' + }, + startTime: [ 1755719307, 782000000 ], + endTime: [ 1755719482, 940000000 ], + value: { + min: 1.439792, + max: 5.775, + sum: 15.370167, + buckets: { + boundaries: [ + 0, 5, 10, 25, + 50, 75, 100, 250, + 500, 750, 1000, 2500, + 5000, 7500, 10000 + ], + counts: [ + 0, 5, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 + ] + }, + count: 6 + } + }, + { + attributes: { + 'http.scheme': 'http', + 'http.method': 'GET', + 'net.host.name': 'localhost', + 'http.flavor': '1.1', + 'http.status_code': 304, + 'net.host.port': 8080, + 'http.route': '/rolldice' + }, + startTime: [ 1755719433, 609000000 ], + endTime: [ 1755719482, 940000000 ], + value: { + min: 1.39575, + max: 1.39575, + sum: 1.39575, + buckets: { + boundaries: [ + 0, 5, 10, 25, + 50, 75, 100, 250, + 500, 750, 1000, 2500, + 5000, 7500, 10000 + ], + counts: [ + 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 + ] + }, + count: 1 + } } ] } { descriptor: { - name: 'http.client.duration', - type: 'HISTOGRAM', - description: 'measures the duration of the outbound HTTP requests', - unit: 'ms', - valueType: 1 - }, - dataPointType: 0, - dataPoints: [] -} -{ - descriptor: { - name: 'db.client.connections.usage', - type: 'UP_DOWN_COUNTER', - description: 'The number of connections that are currently in the state referenced by the attribute "state".', - unit: '{connections}', - valueType: 1 - }, - dataPointType: 3, - dataPoints: [] -} -{ - descriptor: { - name: 'http.server.duration', - type: 'HISTOGRAM', - description: 'measures the duration of the inbound HTTP requests', - unit: 'ms', - valueType: 1 + name: 'nodejs.eventloop.utilization', + type: 'OBSERVABLE_GAUGE', + description: 'Event loop utilization', + unit: '1', + valueType: 1, + advice: {} }, - dataPointType: 0, + dataPointType: 2, dataPoints: [ { - attributes: [Object], - startTime: [Array], - endTime: [Array], - value: [Object] + attributes: {}, + startTime: [ 1755719362, 939000000 ], + endTime: [ 1755719482, 940000000 ], + value: 0.00843049454565211 } ] } { descriptor: { - name: 'http.client.duration', + name: 'v8js.gc.duration', type: 'HISTOGRAM', - description: 'measures the duration of the outbound HTTP requests', - unit: 'ms', - valueType: 1 - }, - dataPointType: 0, - dataPoints: [] -} -{ - descriptor: { - name: 'db.client.connections.usage', - type: 'UP_DOWN_COUNTER', - description: 'The number of connections that are currently in the state referenced by the attribute "state".', - unit: '{connections}', - valueType: 1 - }, - dataPointType: 3, - dataPoints: [] -} -{ - descriptor: { - name: 'http.server.duration', - type: 'HISTOGRAM', - description: 'measures the duration of the inbound HTTP requests', - unit: 'ms', - valueType: 1 + description: 'Garbage collection duration by kind, one of major, minor, incremental or weakcb.', + unit: 's', + valueType: 1, + advice: { explicitBucketBoundaries: [ 0.01, 0.1, 1, 10 ] } }, dataPointType: 0, dataPoints: [ { - attributes: [Object], - startTime: [Array], - endTime: [Array], - value: [Object] + attributes: { 'v8js.gc.type': 'minor' }, + startTime: [ 1755719303, 5000000 ], + endTime: [ 1755719482, 940000000 ], + value: { + min: 0.0005120840072631835, + max: 0.0022552499771118163, + sum: 0.006526499509811401, + buckets: { boundaries: [ 0.01, 0.1, 1, 10 ], counts: [ 6, 0, 0, 0, 0 ] }, + count: 6 + } + }, + { + attributes: { 'v8js.gc.type': 'incremental' }, + startTime: [ 1755719310, 812000000 ], + endTime: [ 1755719482, 940000000 ], + value: { + min: 0.0003403329849243164, + max: 0.0012867081165313721, + sum: 0.0016270411014556885, + buckets: { boundaries: [ 0.01, 0.1, 1, 10 ], counts: [ 2, 0, 0, 0, 0 ] }, + count: 2 + } + }, + { + attributes: { 'v8js.gc.type': 'major' }, + startTime: [ 1755719310, 830000000 ], + endTime: [ 1755719482, 940000000 ], + value: { + min: 0.0025888750553131105, + max: 0.005744750022888183, + sum: 0.008333625078201293, + buckets: { boundaries: [ 0.01, 0.1, 1, 10 ], counts: [ 2, 0, 0, 0, 0 ] }, + count: 2 + } } ] } -{ - descriptor: { - name: 'http.client.duration', - type: 'HISTOGRAM', - description: 'measures the duration of the outbound HTTP requests', - unit: 'ms', - valueType: 1 - }, - dataPointType: 0, - dataPoints: [] -} -{ - descriptor: { - name: 'db.client.connections.usage', - type: 'UP_DOWN_COUNTER', - description: 'The number of connections that are currently in the state referenced by the attribute "state".', - unit: '{connections}', - valueType: 1 - }, - dataPointType: 3, - dataPoints: [] -} ```
@@ -485,9 +521,8 @@ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO); {{% /tab %}} {{% tab JavaScript %}} ```js -/*instrumentation.js*/ -// 依存関係をrequire -const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api'); +/*instrumentation.mjs*/ +import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api'; // トラブルシューティングのために、ログレベルをDiagLogLevel.DEBUGに設定 diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO); diff --git a/content/ja/docs/languages/js/instrumentation.md b/content/ja/docs/languages/js/instrumentation.md index f3cc2b23e4aa..3bb9d5fe36ec 100644 --- a/content/ja/docs/languages/js/instrumentation.md +++ b/content/ja/docs/languages/js/instrumentation.md @@ -43,11 +43,8 @@ npm init -y {{< tabpane text=true >}} {{% tab TypeScript %}} ```sh -npm install typescript \ - ts-node \ - @types/node \ - express \ - @types/express +npm install express @types/express +npm install -D tsx # TypeScript (.ts)ファイルをnodeで直接実行するためのツール ``` {{% /tab %}} {{% tab JavaScript %}} @@ -109,7 +106,7 @@ module.exports = { rollTheDice }; ```ts /*app.ts*/ -import express, { Express } from 'express'; +import express, { type Express } from 'express'; import { rollTheDice } from './dice'; const PORT: number = parseInt(process.env.PORT || '8080'); @@ -164,7 +161,7 @@ app.listen(PORT, () => { {{< tabpane text=true >}} {{% tab TypeScript %}} ```console -$ npx ts-node app.ts +$ npx tsx app.ts Listening for requests on http://localhost:8080 ``` @@ -237,18 +234,18 @@ sdk.start(); {{% /tab %}} {{% tab JavaScript %}} ```js -/*instrumentation.js*/ -const { NodeSDK } = require('@opentelemetry/sdk-node'); -const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node'); -const { +/*instrumentation.mjs*/ +import { NodeSDK } from '@opentelemetry/sdk-node'; +import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node'; +import { PeriodicExportingMetricReader, ConsoleMetricExporter, -} = require('@opentelemetry/sdk-metrics'); -const { resourceFromAttributes } = require('@opentelemetry/resources'); -const { +} from '@opentelemetry/sdk-metrics'; +import { resourceFromAttributes } from '@opentelemetry/resources'; +import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, -} = require('@opentelemetry/semantic-conventions'); +} from '@opentelemetry/semantic-conventions'; const sdk = new NodeSDK({ resource: resourceFromAttributes({ @@ -275,16 +272,23 @@ sdk.start(); コードを確認するには、ライブラリを要求してアプリケーションを実行します。 +{{% alert title="注意" %}} + +以下の`--import instrumentation.ts`(TypeScript)を使用した例は、Node.js v20以降が必要です。 +Node.js v18を使用している場合は、JavaScriptの例を使用してください。 + +{{% /alert %}} + {{< tabpane text=true >}} {{% tab TypeScript %}} ```sh -npx ts-node --require ./instrumentation.ts app.ts +npx tsx --import ./instrumentation.ts app.ts ``` {{% /tab %}} {{% tab JavaScript %}} ```sh -node --require ./instrumentation.js app.js +node --import ./instrumentation.mjs app.js ``` {{% /tab %}} {{< /tabpane >}} @@ -468,7 +472,7 @@ const tracer = opentelemetry.trace.getTracer( ```ts /*app.ts*/ import { trace } from '@opentelemetry/api'; -import express, { Express } from 'express'; +import express, { type Express } from 'express'; import { rollTheDice } from './dice'; const tracer = trace.getTracer('dice-server', '0.1.0'); @@ -587,7 +591,7 @@ OpenTelemetry JavaScript APIは、スパンを作成できる2つのメソッド {{< tabpane text=true >}} {{% tab TypeScript %}} ```ts -import { trace, Span } from '@opentelemetry/api'; +import { trace, type Span } from '@opentelemetry/api'; /* ... */ @@ -632,13 +636,13 @@ function rollTheDice(rolls, min, max) { {{< tabpane text=true >}} {{% tab TypeScript %}} ```sh -ts-node --require ./instrumentation.ts app.ts +npx tsx --import ./instrumentation.ts app.ts ``` {{% /tab %}} {{% tab JavaScript %}} ```sh -node --require ./instrumentation.js app.js +node --import ./instrumentation.mjs app.js ``` {{% /tab %}} {{< /tabpane >}} @@ -646,19 +650,28 @@ node --require ./instrumentation.js app.js しばらくすると、`ConsoleSpanExporter`によってコンソールにスパンが出力されるのが表示されるはずです。 次のようなものです。 -```json +```js { - "traceId": "6cc927a05e7f573e63f806a2e9bb7da8", - "parentId": undefined, - "name": "rollTheDice", - "id": "117d98e8add5dc80", - "kind": 0, - "timestamp": 1688386291908349, - "duration": 501, - "attributes": {}, - "status": { "code": 0 }, - "events": [], - "links": [] + resource: { + attributes: { + 'service.name': 'dice-server', + 'service.version': '0.1.0', + // ... + } + }, + instrumentationScope: { name: 'dice-lib', version: undefined, schemaUrl: undefined }, + traceId: '30d32251088ba9d9bca67b09c43dace0', + parentSpanContext: undefined, + traceState: undefined, + name: 'rollTheDice', + id: 'cc8a67c2d4840402', + kind: 0, + timestamp: 1756165206470000, + duration: 35.584, + attributes: {}, + status: { code: 0 }, + events: [], + links: [] } ``` @@ -722,32 +735,41 @@ function rollTheDice(rolls, min, max) { このコードは、各 _ロール_ に対して、`parentSpan`のIDを親IDとして持つ子スパンを作成します。 -```json +```js +{ + traceId: '6469e115dc1562dd768c999da0509615', + parentSpanContext: { + traceId: '6469e115dc1562dd768c999da0509615', + spanId: '38691692d6bc3395', + // ... + }, + name: 'rollOnce:0', + id: '36423bc1ce7532b0', + timestamp: 1756165362215000, + duration: 85.667, + // ... +} { - "traceId": "ff1d39e648a3dc53ba710e1bf1b86e06", - "parentId": "9214ff209e6a8267", - "name": "rollOnce:4", - "id": "7eccf70703e2bccd", - "kind": 0, - "timestamp": 1688387049511591, - "duration": 22, - "attributes": {}, - "status": { "code": 0 }, - "events": [], - "links": [] + traceId: '6469e115dc1562dd768c999da0509615', + parentSpanContext: { + traceId: '6469e115dc1562dd768c999da0509615', + spanId: '38691692d6bc3395', + // ... + }, + name: 'rollOnce:1', + id: 'ed9bbba2264d6872', + timestamp: 1756165362215000, + duration: 16.834, + // ... } { - "traceId": "ff1d39e648a3dc53ba710e1bf1b86e06", - "parentId": undefined, - "name": "rollTheDice", - "id": "9214ff209e6a8267", - "kind": 0, - "timestamp": 1688387049510303, - "duration": 1314, - "attributes": {}, - "status": { "code": 0 }, - "events": [], - "links": [] + traceId: '6469e115dc1562dd768c999da0509615', + parentSpanContext: undefined, + name: 'rollTheDice', + id: '38691692d6bc3395', + timestamp: 1756165362214000, + duration: 1022.209, + // ... } ``` @@ -756,7 +778,7 @@ function rollTheDice(rolls, min, max) { 前の例では、アクティブなスパンを作成する方法を示しました。 場合によっては、ネストされているのではなく、互いに兄弟である非アクティブなスパンを作成したいことがあります。 -```javascript +```js const doWork = () => { const span1 = tracer.startSpan('work-1'); // 何かの作業 @@ -896,8 +918,8 @@ npm install --save @opentelemetry/semantic-conventions ```ts import { - SEMATTRS_CODE_FUNCTION, - SEMATTRS_CODE_FILEPATH, + ATTR_CODE_FUNCTION_NAME, + ATTR_CODE_FILE_PATH, } from '@opentelemetry/semantic-conventions'; ``` @@ -905,8 +927,8 @@ import { ```js const { - SEMATTRS_CODE_FUNCTION, - SEMATTRS_CODE_FILEPATH, + ATTR_CODE_FUNCTION_NAME, + ATTR_CODE_FILE_PATH, } = require('@opentelemetry/semantic-conventions'); ``` @@ -914,11 +936,11 @@ const { 最後に、セマンティック属性を含めるようにファイルを更新できます。 -```javascript +```js const doWork = () => { tracer.startActiveSpan('app.doWork', (span) => { - span.setAttribute(SEMATTRS_CODE_FUNCTION, 'doWork'); - span.setAttribute(SEMATTRS_CODE_FILEPATH, __filename); + span.setAttribute(ATTR_CODE_FUNCTION_NAME, 'doWork'); + span.setAttribute(ATTR_CODE_FILE_PATH, __filename); // 何かの作業を行う... @@ -1295,18 +1317,18 @@ opentelemetry.metrics.setGlobalMeterProvider(myServiceMeterProvider); {{% /tab %}} {{< /tabpane >}} -アプリケーションを実行するときに、このファイルを`--require`する必要があります。 +アプリケーションを実行するときに、このファイルを`--import`する必要があります。 {{< tabpane text=true >}} {{% tab TypeScript %}} ```sh -ts-node --require ./instrumentation.ts app.ts +npx tsx --import ./instrumentation.ts app.ts ``` {{% /tab %}} {{% tab JavaScript %}} ```sh -node --require ./instrumentation.js app.js +node --import ./instrumentation.mjs app.js ``` {{% /tab %}} {{< /tabpane >}} @@ -1361,7 +1383,7 @@ const myMeter = opentelemetry.metrics.getMeter( ```ts /*app.ts*/ import { metrics, trace } from '@opentelemetry/api'; -import express, { Express } from 'express'; +import express, { type Express } from 'express'; import { rollTheDice } from './dice'; const tracer = trace.getTracer('dice-server', '0.1.0'); diff --git a/content/ja/docs/languages/js/libraries.md b/content/ja/docs/languages/js/libraries.md index 5f3fda06a2a8..099bf84d0e0e 100644 --- a/content/ja/docs/languages/js/libraries.md +++ b/content/ja/docs/languages/js/libraries.md @@ -3,8 +3,7 @@ title: 計装ライブラリの使用 linkTitle: ライブラリ weight: 40 description: アプリが依存するライブラリをインストルメントする方法 -default_lang_commit: 6f3712c5cda4ea79f75fb410521880396ca30c91 # patched -drifted_from_default: true +default_lang_commit: 276d7eb3f936deef6487cdd2b1d89822951da6c8 --- {{% docs/languages/libraries-intro "js" %}} @@ -189,7 +188,7 @@ const sdk = new NodeSDK({ 一部の計装ライブラリは追加の設定オプションを提供しています。 -たとえば、[Express計装](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/52dd28deae0ebfbec43bdaed82f4749fc9803797/plugins/node/opentelemetry-instrumentation-express#express-instrumentation-options)は、指定されたミドルウェアを無視したり、リクエストフックで自動的に作成されるスパンを強化したりする方法を提供しています。 +たとえば、[Express計装](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express#express-instrumentation-options)は、指定されたミドルウェアを無視したり、リクエストフックで自動的に作成されるスパンを強化したりする方法を提供しています。 {{< tabpane text=true >}} diff --git a/content/ja/docs/languages/js/propagation.md b/content/ja/docs/languages/js/propagation.md index ba314a592d6e..b489b174039c 100644 --- a/content/ja/docs/languages/js/propagation.md +++ b/content/ja/docs/languages/js/propagation.md @@ -2,12 +2,11 @@ title: 伝搬 description: JS SDKのコンテキスト伝搬 weight: 65 -default_lang_commit: 6f3712c5cda4ea79f75fb410521880396ca30c91 -drifted_from_default: true +default_lang_commit: 276d7eb3f936deef6487cdd2b1d89822951da6c8 cSpell:ignore: rolldice --- -{{% docs/languages/propagation js %}} +{{% docs/languages/propagation %}} ## 自動コンテキスト伝搬 {#automatic-context-propagation} @@ -27,15 +26,10 @@ cSpell:ignore: rolldice ```sh npm init -y -npm install typescript \ - ts-node \ - @types/node \ - undici \ +npm install undici \ @opentelemetry/instrumentation-undici \ @opentelemetry/sdk-node - -# TypeScriptを初期化 -npx tsc --init +npm install -D tsx # TypeScript (.ts)ファイルをnodeで直接実行するためのツール ``` {{% /tab %}} {{% tab JavaScript %}} @@ -49,11 +43,12 @@ npm install undici \ {{% /tab %}} {{< /tabpane >}} -次に、`client.ts`(またはclient.js)という新しいファイルを以下の内容で作成します。 +次に、`client.ts`(または`client.js`)という新しいファイルを以下の内容で作成します。 {{< tabpane text=true >}} {{% tab TypeScript %}} ```ts +/* client.ts */ import { NodeSDK } from '@opentelemetry/sdk-node'; import { SimpleSpanProcessor, @@ -77,14 +72,13 @@ request('http://localhost:8080/rolldice').then((response) => { {{% /tab %}} {{% tab JavaScript %}} ```js -const { NodeSDK } = require('@opentelemetry/sdk-node'); -const { +/* instrumentation.mjs */ +import { NodeSDK } from '@opentelemetry/sdk-node'; +import { SimpleSpanProcessor, ConsoleSpanExporter, -} = require('@opentelemetry/sdk-trace-node'); -const { - UndiciInstrumentation, -} = require('@opentelemetry/instrumentation-undici'); +} from '@opentelemetry/sdk-trace-node'; +import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici'; const sdk = new NodeSDK({ spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())], @@ -106,14 +100,14 @@ request('http://localhost:8080/rolldice').then((response) => { {{< tabpane text=true >}} {{% tab TypeScript %}} ```console -$ npx ts-node --require ./instrumentation.ts app.ts +$ npx tsx --import ./instrumentation.ts app.ts Listening for requests on http://localhost:8080 ``` {{% /tab %}} {{% tab JavaScript %}} ```console -$ node --require ./instrumentation.js app.js +$ node --import ./instrumentation.mjs app.js Listening for requests on http://localhost:8080 ``` @@ -124,7 +118,7 @@ Listening for requests on http://localhost:8080 {{< tabpane text=true >}} {{% tab TypeScript %}} ```shell -npx ts-node client.ts +npx tsx client.ts ``` {{% /tab %}} {{% tab JavaScript %}} @@ -146,7 +140,7 @@ node client.js } }, traceId: 'cccd19c3a2d10e589f01bfe2dc896dc2', - parentId: undefined, + parentSpanContext: undefined, traceState: undefined, name: 'GET', id: '6f64ce484217a7bf', @@ -166,14 +160,19 @@ node client.js traceId(`cccd19c3a2d10e589f01bfe2dc896dc2`)とID(`6f64ce484217a7bf`)をメモしてください。 両方はクライアントの出力でも見つけることができます。 -```javascript {hl_lines=["6-7"]} +```javascript {hl_lines=[6,9]} { resource: { attributes: { // ... }, traceId: 'cccd19c3a2d10e589f01bfe2dc896dc2', - parentId: '6f64ce484217a7bf', + parentSpanContext: { + traceId: 'cccd19c3a2d10e589f01bfe2dc896dc2', + spanId: '6f64ce484217a7bf', + traceFlags: 1, + isRemote: true + }, traceState: undefined, name: 'GET /rolldice', id: '027c5c8b916d29da', @@ -446,12 +445,12 @@ Parsed JSON: { key: 'value' } OpenTelemetryを有効にし、実際のコンテキスト伝搬を確認するために、以下の内容で`instrumentation.js`という追加ファイルを作成します。 ```javascript -// instrumentation.js -const { NodeSDK } = require('@opentelemetry/sdk-node'); -const { +// instrumentation.mjs +import { NodeSDK } from '@opentelemetry/sdk-node'; +import { ConsoleSpanExporter, SimpleSpanProcessor, -} = require('@opentelemetry/sdk-trace-node'); +} from '@opentelemetry/sdk-trace-node'; const sdk = new NodeSDK({ spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())], @@ -463,14 +462,14 @@ sdk.start(); このファイルを使用して、計装を有効にしてサーバーとクライアントの両方を実行します。 ```console -$ node -r ./instrumentation.js server.js +$ node --import ./instrumentation.mjs server.js Server listening on port 8124 ``` および ```shell -node -r ./instrumentation client.js +node --import ./instrumentation.mjs client.js ``` クライアントがサーバーにデータを送信して終了した後、両方のシェルのコンソール出力にスパンが表示されるはずです。 diff --git a/content/ja/docs/languages/js/resources.md b/content/ja/docs/languages/js/resources.md index 3c9e86ca1258..497199531472 100644 --- a/content/ja/docs/languages/js/resources.md +++ b/content/ja/docs/languages/js/resources.md @@ -2,8 +2,7 @@ title: リソース weight: 70 description: アプリケーションの環境に関する詳細情報をテレメトリに追加する -default_lang_commit: 6f3712c5cda4ea79f75fb410521880396ca30c91 # patched -drifted_from_default: true +default_lang_commit: 276d7eb3f936deef6487cdd2b1d89822951da6c8 cSpell:ignore: myhost SIGINT uuidgen WORKDIR --- @@ -237,7 +236,7 @@ DockerCGroupV1Detector found resource. Resource { 設定に追加できるリソース検出器は他にもあります。 たとえば、[Cloud]環境や[Deployment]の詳細を取得するものがあります。 -詳細については、[検出器の完全なリスト](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/52dd28deae0ebfbec43bdaed82f4749fc9803797/detectors/node)を参照してください。 +詳細については、[opentelemetry-js-contribリポジトリの`resource-detector-*`という名前のパッケージ](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages)を参照してください。 [getting started - node.js]: /docs/languages/js/getting-started/nodejs/ [process and process runtime resources]: /docs/specs/semconv/resource/process/