Skip to content

Commit d74419e

Browse files
authored
Merge pull request #25 from quintoandar/span-attributes-info
Span attributes info
2 parents 72dfba5 + e177b44 commit d74419e

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Winston logger with sentry configuration included. Also show the module, file pa
1212
| NODE_ENV | The application environment running (development, test, production) |
1313
| PRETTY_LOGS | Enable colored logs with clean spacing |
1414
| JSON_LOGS | Enable structured logs as JSON |
15+
| SPAN_INFO | Enable span context info on logs |
1516
| SENTRY_APP | The application's name |
1617
| SENTRY_DSN | Sentry's DNS |
1718
| SENTRY_ENVIRONMENT | The environment running (dev, staging, prod) |

src/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { obfuscate } = require('./obfuscate')
1212

1313
const prettyLogs = process.env.PRETTY_LOGS;
1414
const json_logs = process.env.JSON_LOGS;
15+
const span_info = process.env.SPAN_INFO;
1516
const winstonTransports = [
1617
sentryTransport,
1718
json_logs ? consoleTransportJson : consoleTransport,
@@ -59,12 +60,15 @@ function formatParams(params, module, funcCallerParam) {
5960
const metadata = {};
6061

6162
if (tracer && tracer.currentRootSpan && tracer.currentRootSpan.traceId) {
62-
const allDescendants = tracer.currentRootSpan.allDescendants().map((span) => span.id)
6363
metadata.traceId = tracer.currentRootSpan.traceId;
64-
metadata.spans = {
65-
parentSpanId: tracer.currentRootSpan.parentSpanId ? tracer.currentRootSpan.parentSpanId : null,
66-
spanId: tracer.currentRootSpan.id,
67-
descendants: allDescendants,
64+
if (span_info) {
65+
const allDescendants = tracer.currentRootSpan.allDescendants().map((span) => span.id)
66+
metadata.rootSpan = {
67+
parentSpanId: tracer.currentRootSpan.parentSpanId ? tracer.currentRootSpan.parentSpanId : null,
68+
spanId: tracer.currentRootSpan.id,
69+
descendants: allDescendants,
70+
attributes: tracer.currentRootSpan.attributes
71+
}
6872
}
6973
}
7074

src/transports.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ let loggerFormat = format.combine(
8888
if (info.traceId) {
8989
out += ` [trace-id: ${info.traceId}]`;
9090
}
91-
if (metadata && metadata.spanId) {
92-
out += ` [span-id: ${metadata.spanId}]`;
93-
}
9491

9592
const error = info.metadata.error;
9693

0 commit comments

Comments
 (0)