Skip to content

Commit a8c950d

Browse files
docs: Documentation update for OpenTelemetry and tracing (#1517)
* docs: Documentation update for OpenTelemetry and tracing * fix lint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update documentation * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix comments * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 5b57cdb commit a8c950d

7 files changed

+112
-86
lines changed

.readme-partials.yml

+13
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ body: |-
8080
If you already have a "raw" Http `request` object you can assign it to `entry.metadata.httpRequest` directly. More information about
8181
how the `request` is interpreted as raw can be found in the [code](https://github.com/googleapis/nodejs-logging/blob/15849160116a814ab71113138cb211c2e0c2d4b4/src/entry.ts#L224-L238).
8282
83+
## Automatic Trace/Span ID Extraction
84+
Cloud Logging libraries use [trace fields within LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace) to capture trace contexts, which enables the [correlation of logs and traces](https://cloud.google.com/logging/docs/view/correlate-logs), and distributed tracing troubleshooting.
85+
These tracing fields, including [trace](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace), [spanId](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.span_id), and [traceSampled](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace_sampled), define the trace context for a `LogEntry`.
86+
87+
If not provided explicitly in a LogEntry, the Cloud Logging library automatically populates `trace`, `span_id`, and `trace_sampled` fields from detected OpenTelemetry span contexts, or from HTTP request headers.
88+
89+
### Extracting Trace/Span ID from OpenTelemetry Context
90+
If you are using OpenTelemetry and there is an active span in the OpenTelemetry Context, the `trace`, `span_id`, and `trace_sampled` fields in the log entry are automatically populated from the active span. More information about OpenTelemetry can be found [here](https://opentelemetry.io/docs/languages/js/).
91+
92+
### Extracting Trace/Span ID from HTTP Headers
93+
If tracing fields are not provided explicitly and no OpenTelemetry context is detected, the `trace` / `span_id` fields are extracted automatically from HTTP headers.
94+
Trace information can be automatically populated from either the [W3C Traceparent](https://www.w3.org/TR/trace-context) or [X-Cloud-Trace-Context](https://cloud.google.com/trace/docs/trace-context#legacy-http-header) headers.
95+
8396
## Error handling with logs written or deleted asynchronously
8497
8598
The `Log` class provide users the ability to write and delete logs asynchronously. However, there are cases when log entries

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ how to populate the Http request metadata for log entries.
170170
If you already have a "raw" Http `request` object you can assign it to `entry.metadata.httpRequest` directly. More information about
171171
how the `request` is interpreted as raw can be found in the [code](https://github.com/googleapis/nodejs-logging/blob/15849160116a814ab71113138cb211c2e0c2d4b4/src/entry.ts#L224-L238).
172172
173+
## Automatic Trace/Span ID Extraction
174+
Cloud Logging libraries use [trace fields within LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace) to capture trace contexts, which enables the [correlation of logs and traces](https://cloud.google.com/logging/docs/view/correlate-logs), and distributed tracing troubleshooting.
175+
These tracing fields, including [trace](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace), [spanId](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.span_id), and [traceSampled](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace_sampled), define the trace context for a `LogEntry`.
176+
177+
If not provided explicitly in a LogEntry, the Cloud Logging library automatically populates `trace`, `span_id`, and `trace_sampled` fields from detected OpenTelemetry span contexts, or from HTTP request headers.
178+
179+
### Extracting Trace/Span ID from OpenTelemetry Context
180+
If you are using OpenTelemetry and there is an active span in the OpenTelemetry Context, the `trace`, `span_id`, and `trace_sampled` fields in the log entry are automatically populated from the active span. More information about OpenTelemetry can be found [here](https://opentelemetry.io/docs/languages/js/).
181+
182+
### Extracting Trace/Span ID from HTTP Headers
183+
If tracing fields are not provided explicitly and no OpenTelemetry context is detected, the `trace` / `span_id` fields are extracted automatically from HTTP headers.
184+
Trace information can be automatically populated from either the [W3C Traceparent](https://www.w3.org/TR/trace-context) or [X-Cloud-Trace-Context](https://cloud.google.com/trace/docs/trace-context#legacy-http-header) headers.
185+
173186
## Error handling with logs written or deleted asynchronously
174187
175188
The `Log` class provide users the ability to write and delete logs asynchronously. However, there are cases when log entries

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {callbackifyAll} from '@google-cloud/promisify';
2121
import arrify = require('arrify');
2222
import * as extend from 'extend';
2323
import * as gax from 'google-gax';
24-
// eslint-disable-next-line node/no-extraneous-import
24+
// eslint-disable-next-line n/no-extraneous-import
2525
import {ClientReadableStream, ClientDuplexStream} from '@grpc/grpc-js';
2626
// eslint-disable-next-line @typescript-eslint/no-var-requires
2727
const pumpify = require('pumpify');

system-test/fixtures/sample/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// ** https://github.com/googleapis/gapic-generator-typescript **
1717
// ** All changes to this file may be overwritten. **
1818

19-
/* eslint-disable node/no-missing-require, no-unused-vars */
19+
/* eslint-disable n/no-missing-require, no-unused-vars */
2020
const logging = require('@google-cloud/logging');
2121

2222
function main() {

test/gapic_config_service_v2_v2.ts

+60-60
Original file line numberDiff line numberDiff line change
@@ -4251,9 +4251,9 @@ describe('v2.ConfigServiceV2Client', () => {
42514251
assert(
42524252
(client.descriptors.page.listBuckets.createStream as SinonStub)
42534253
.getCall(0)
4254-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4255-
expectedHeaderRequestParams
4256-
)
4254+
.args[2].otherArgs.headers[
4255+
'x-goog-request-params'
4256+
].includes(expectedHeaderRequestParams)
42574257
);
42584258
});
42594259

@@ -4299,9 +4299,9 @@ describe('v2.ConfigServiceV2Client', () => {
42994299
assert(
43004300
(client.descriptors.page.listBuckets.createStream as SinonStub)
43014301
.getCall(0)
4302-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4303-
expectedHeaderRequestParams
4304-
)
4302+
.args[2].otherArgs.headers[
4303+
'x-goog-request-params'
4304+
].includes(expectedHeaderRequestParams)
43054305
);
43064306
});
43074307

@@ -4342,9 +4342,9 @@ describe('v2.ConfigServiceV2Client', () => {
43424342
assert(
43434343
(client.descriptors.page.listBuckets.asyncIterate as SinonStub)
43444344
.getCall(0)
4345-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4346-
expectedHeaderRequestParams
4347-
)
4345+
.args[2].otherArgs.headers[
4346+
'x-goog-request-params'
4347+
].includes(expectedHeaderRequestParams)
43484348
);
43494349
});
43504350

@@ -4384,9 +4384,9 @@ describe('v2.ConfigServiceV2Client', () => {
43844384
assert(
43854385
(client.descriptors.page.listBuckets.asyncIterate as SinonStub)
43864386
.getCall(0)
4387-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4388-
expectedHeaderRequestParams
4389-
)
4387+
.args[2].otherArgs.headers[
4388+
'x-goog-request-params'
4389+
].includes(expectedHeaderRequestParams)
43904390
);
43914391
});
43924392
});
@@ -4547,9 +4547,9 @@ describe('v2.ConfigServiceV2Client', () => {
45474547
assert(
45484548
(client.descriptors.page.listViews.createStream as SinonStub)
45494549
.getCall(0)
4550-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4551-
expectedHeaderRequestParams
4552-
)
4550+
.args[2].otherArgs.headers[
4551+
'x-goog-request-params'
4552+
].includes(expectedHeaderRequestParams)
45534553
);
45544554
});
45554555

@@ -4595,9 +4595,9 @@ describe('v2.ConfigServiceV2Client', () => {
45954595
assert(
45964596
(client.descriptors.page.listViews.createStream as SinonStub)
45974597
.getCall(0)
4598-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4599-
expectedHeaderRequestParams
4600-
)
4598+
.args[2].otherArgs.headers[
4599+
'x-goog-request-params'
4600+
].includes(expectedHeaderRequestParams)
46014601
);
46024602
});
46034603

@@ -4637,9 +4637,9 @@ describe('v2.ConfigServiceV2Client', () => {
46374637
assert(
46384638
(client.descriptors.page.listViews.asyncIterate as SinonStub)
46394639
.getCall(0)
4640-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4641-
expectedHeaderRequestParams
4642-
)
4640+
.args[2].otherArgs.headers[
4641+
'x-goog-request-params'
4642+
].includes(expectedHeaderRequestParams)
46434643
);
46444644
});
46454645

@@ -4678,9 +4678,9 @@ describe('v2.ConfigServiceV2Client', () => {
46784678
assert(
46794679
(client.descriptors.page.listViews.asyncIterate as SinonStub)
46804680
.getCall(0)
4681-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4682-
expectedHeaderRequestParams
4683-
)
4681+
.args[2].otherArgs.headers[
4682+
'x-goog-request-params'
4683+
].includes(expectedHeaderRequestParams)
46844684
);
46854685
});
46864686
});
@@ -4841,9 +4841,9 @@ describe('v2.ConfigServiceV2Client', () => {
48414841
assert(
48424842
(client.descriptors.page.listSinks.createStream as SinonStub)
48434843
.getCall(0)
4844-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4845-
expectedHeaderRequestParams
4846-
)
4844+
.args[2].otherArgs.headers[
4845+
'x-goog-request-params'
4846+
].includes(expectedHeaderRequestParams)
48474847
);
48484848
});
48494849

@@ -4889,9 +4889,9 @@ describe('v2.ConfigServiceV2Client', () => {
48894889
assert(
48904890
(client.descriptors.page.listSinks.createStream as SinonStub)
48914891
.getCall(0)
4892-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4893-
expectedHeaderRequestParams
4894-
)
4892+
.args[2].otherArgs.headers[
4893+
'x-goog-request-params'
4894+
].includes(expectedHeaderRequestParams)
48954895
);
48964896
});
48974897

@@ -4931,9 +4931,9 @@ describe('v2.ConfigServiceV2Client', () => {
49314931
assert(
49324932
(client.descriptors.page.listSinks.asyncIterate as SinonStub)
49334933
.getCall(0)
4934-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4935-
expectedHeaderRequestParams
4936-
)
4934+
.args[2].otherArgs.headers[
4935+
'x-goog-request-params'
4936+
].includes(expectedHeaderRequestParams)
49374937
);
49384938
});
49394939

@@ -4972,9 +4972,9 @@ describe('v2.ConfigServiceV2Client', () => {
49724972
assert(
49734973
(client.descriptors.page.listSinks.asyncIterate as SinonStub)
49744974
.getCall(0)
4975-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
4976-
expectedHeaderRequestParams
4977-
)
4975+
.args[2].otherArgs.headers[
4976+
'x-goog-request-params'
4977+
].includes(expectedHeaderRequestParams)
49784978
);
49794979
});
49804980
});
@@ -5135,9 +5135,9 @@ describe('v2.ConfigServiceV2Client', () => {
51355135
assert(
51365136
(client.descriptors.page.listLinks.createStream as SinonStub)
51375137
.getCall(0)
5138-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5139-
expectedHeaderRequestParams
5140-
)
5138+
.args[2].otherArgs.headers[
5139+
'x-goog-request-params'
5140+
].includes(expectedHeaderRequestParams)
51415141
);
51425142
});
51435143

@@ -5183,9 +5183,9 @@ describe('v2.ConfigServiceV2Client', () => {
51835183
assert(
51845184
(client.descriptors.page.listLinks.createStream as SinonStub)
51855185
.getCall(0)
5186-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5187-
expectedHeaderRequestParams
5188-
)
5186+
.args[2].otherArgs.headers[
5187+
'x-goog-request-params'
5188+
].includes(expectedHeaderRequestParams)
51895189
);
51905190
});
51915191

@@ -5225,9 +5225,9 @@ describe('v2.ConfigServiceV2Client', () => {
52255225
assert(
52265226
(client.descriptors.page.listLinks.asyncIterate as SinonStub)
52275227
.getCall(0)
5228-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5229-
expectedHeaderRequestParams
5230-
)
5228+
.args[2].otherArgs.headers[
5229+
'x-goog-request-params'
5230+
].includes(expectedHeaderRequestParams)
52315231
);
52325232
});
52335233

@@ -5266,9 +5266,9 @@ describe('v2.ConfigServiceV2Client', () => {
52665266
assert(
52675267
(client.descriptors.page.listLinks.asyncIterate as SinonStub)
52685268
.getCall(0)
5269-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5270-
expectedHeaderRequestParams
5271-
)
5269+
.args[2].otherArgs.headers[
5270+
'x-goog-request-params'
5271+
].includes(expectedHeaderRequestParams)
52725272
);
52735273
});
52745274
});
@@ -5432,9 +5432,9 @@ describe('v2.ConfigServiceV2Client', () => {
54325432
assert(
54335433
(client.descriptors.page.listExclusions.createStream as SinonStub)
54345434
.getCall(0)
5435-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5436-
expectedHeaderRequestParams
5437-
)
5435+
.args[2].otherArgs.headers[
5436+
'x-goog-request-params'
5437+
].includes(expectedHeaderRequestParams)
54385438
);
54395439
});
54405440

@@ -5478,9 +5478,9 @@ describe('v2.ConfigServiceV2Client', () => {
54785478
assert(
54795479
(client.descriptors.page.listExclusions.createStream as SinonStub)
54805480
.getCall(0)
5481-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5482-
expectedHeaderRequestParams
5483-
)
5481+
.args[2].otherArgs.headers[
5482+
'x-goog-request-params'
5483+
].includes(expectedHeaderRequestParams)
54845484
);
54855485
});
54865486

@@ -5521,9 +5521,9 @@ describe('v2.ConfigServiceV2Client', () => {
55215521
assert(
55225522
(client.descriptors.page.listExclusions.asyncIterate as SinonStub)
55235523
.getCall(0)
5524-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5525-
expectedHeaderRequestParams
5526-
)
5524+
.args[2].otherArgs.headers[
5525+
'x-goog-request-params'
5526+
].includes(expectedHeaderRequestParams)
55275527
);
55285528
});
55295529

@@ -5561,9 +5561,9 @@ describe('v2.ConfigServiceV2Client', () => {
55615561
assert(
55625562
(client.descriptors.page.listExclusions.asyncIterate as SinonStub)
55635563
.getCall(0)
5564-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
5565-
expectedHeaderRequestParams
5566-
)
5564+
.args[2].otherArgs.headers[
5565+
'x-goog-request-params'
5566+
].includes(expectedHeaderRequestParams)
55675567
);
55685568
});
55695569
});

test/gapic_logging_service_v2_v2.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,9 @@ describe('v2.LoggingServiceV2Client', () => {
12061206
assert(
12071207
(client.descriptors.page.listLogs.createStream as SinonStub)
12081208
.getCall(0)
1209-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
1210-
expectedHeaderRequestParams
1211-
)
1209+
.args[2].otherArgs.headers[
1210+
'x-goog-request-params'
1211+
].includes(expectedHeaderRequestParams)
12121212
);
12131213
});
12141214

@@ -1254,9 +1254,9 @@ describe('v2.LoggingServiceV2Client', () => {
12541254
assert(
12551255
(client.descriptors.page.listLogs.createStream as SinonStub)
12561256
.getCall(0)
1257-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
1258-
expectedHeaderRequestParams
1259-
)
1257+
.args[2].otherArgs.headers[
1258+
'x-goog-request-params'
1259+
].includes(expectedHeaderRequestParams)
12601260
);
12611261
});
12621262

@@ -1292,9 +1292,9 @@ describe('v2.LoggingServiceV2Client', () => {
12921292
assert(
12931293
(client.descriptors.page.listLogs.asyncIterate as SinonStub)
12941294
.getCall(0)
1295-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
1296-
expectedHeaderRequestParams
1297-
)
1295+
.args[2].otherArgs.headers[
1296+
'x-goog-request-params'
1297+
].includes(expectedHeaderRequestParams)
12981298
);
12991299
});
13001300

@@ -1333,9 +1333,9 @@ describe('v2.LoggingServiceV2Client', () => {
13331333
assert(
13341334
(client.descriptors.page.listLogs.asyncIterate as SinonStub)
13351335
.getCall(0)
1336-
.args[2].otherArgs.headers['x-goog-request-params'].includes(
1337-
expectedHeaderRequestParams
1338-
)
1336+
.args[2].otherArgs.headers[
1337+
'x-goog-request-params'
1338+
].includes(expectedHeaderRequestParams)
13391339
);
13401340
});
13411341
});

0 commit comments

Comments
 (0)