Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate SpanIDs and TraceIDs from logs picked via filelog receiver #27283

Closed
ceevaaa opened this issue Sep 30, 2023 · 6 comments
Closed

Populate SpanIDs and TraceIDs from logs picked via filelog receiver #27283

ceevaaa opened this issue Sep 30, 2023 · 6 comments
Labels
bug Something isn't working processor/transform Transform processor receiver/filelog

Comments

@ceevaaa
Copy link

ceevaaa commented Sep 30, 2023

Component(s)

processor/transform, receiver/filelog

What happened?

Description

I want to populate the TraceID and SpanID fields (in the exported OTLP logs) from the logs picked by the filelog receiver.

An entry from a log looks like this -
{"level":"info","traceId":"f5f510d734d6df8e51ffa998d2045199","spanId":"923e0d2c44e6b43a","additionalData":null,"requestId":"","location":"main.(*application).history","time":"2023-09-27T19:18:44.034049083Z","message":"blah"}

The output from filelog receiver looks something like -

Sep 30 22:34:38 LMAO otelcol-contrib[16706]: LogRecord #0
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: ObservedTimestamp: 2023-09-30 17:04:38.184352971 +0000 UTC
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: Timestamp: 2023-09-27 19:18:44.034049083 +0000 UTC
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: SeverityText: info
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: SeverityNumber: Info(9)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: Body: Str(blah)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: Attributes:
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> requestId: Str()
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> level: Str(info)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> traceId: Str(f5f510d734d6df8e51ffa998d2045199)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> additionalData: Str(<nil>)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> spanId: Str(923e0d2c44e6b43a)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> fyId: Str()
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> location: Str(main.(*application).historyWebHandler.func1[history_web.go:16])
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> time: Str(2023-09-27T19:18:44.034049083Z)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> message: Str(History Web Handler)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]:      -> log.file.name: Str(gg.log)
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: Trace ID:
Sep 30 22:34:38 LMAO otelcol-contrib[16706]: Span ID:

Can I do this via the filelog receiver itself ? Or i will need to do this using the transform processor ?
Either way can someone please point me to the exact expression I will need to write to populate these ?

Thanks and Regards

Collector version

v0.83.0

Environment information

Environment

OS: (e.g., "Ubuntu 22.04")

OpenTelemetry Collector configuration

filelog:
    include:
      - /gg.log
    start_at: beginning
    operators:
      - type: filter
        expr: 'body matches "GIN"'
      - type: filter
        expr: 'body matches "gin"'
      - type: filter
        expr: 'body matches "INF"'
      - type: json_parser
      - type: severity_parser
        parse_from: attributes["level"]
        preset: default
      - type: time_parser
        parse_from: attributes["time"]
        layout: "%Y-%m-%dT%H:%M:%S.%LZ"

Log output

No response

Additional context

No response

@ceevaaa ceevaaa added bug Something isn't working needs triage New item requiring triage labels Sep 30, 2023
@ceevaaa ceevaaa changed the title [] Populate SpanIDs and TraceIDs from logs picked via filelog receiver Populate SpanIDs and TraceIDs from logs picked via filelog receiver Sep 30, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot removed the needs triage New item requiring triage label Sep 30, 2023
@ceevaaa
Copy link
Author

ceevaaa commented Sep 30, 2023

/label -bug -needs-triage

@ceevaaa
Copy link
Author

ceevaaa commented Oct 1, 2023

/label +question -bug

@ceevaaa
Copy link
Author

ceevaaa commented Oct 2, 2023

This worked for me.

- set(trace_id.string, attributes["traceId"]) where attributes["traceId"] != nil and IsString(attributes["traceId"]) == true
- set(span_id.string, attributes["spanId"]) where attributes["spanId"] != nil and IsString(attributes["spanId"]) == true

@ceevaaa ceevaaa closed this as completed Oct 2, 2023
@djaglowski
Copy link
Member

You can also do this within the receiver. See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/types/trace.md#trace-parsing

@ceevaaa
Copy link
Author

ceevaaa commented Oct 2, 2023

God! I missed that. Thanks for pointing that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working processor/transform Transform processor receiver/filelog
Projects
None yet
Development

No branches or pull requests

2 participants