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

Adding log attributes to resource attributes #26989

Closed
sairamsadanala opened this issue Sep 18, 2023 · 6 comments
Closed

Adding log attributes to resource attributes #26989

sairamsadanala opened this issue Sep 18, 2023 · 6 comments
Labels
needs triage New item requiring triage processor/resource Resource processor processor/transform Transform processor question Further information is requested

Comments

@sairamsadanala
Copy link

Component(s)

processor/resource

What happened?

Description

Setting up otelcol-contrib abstraction layer to receive telemetry having multiple exporter (loki and Splunk). Otel-hub extracts Kubernetes namespace from log body using Transform processor and set loki.tenant hint so that loki exporter can send to Loki endpoint. Logs need to be routed b/w loki and Splunk based on namespace attributes. Currently i have the namespace in log attributes but Routing processor only support context(header) or resource attributes and hence trying to set resource attribute from log attribute.

Steps to Reproduce

transform:
error_mode: ignore
log_statements:
- context: log
statements:
- set(attributes["cache"], ParseJSON(body)) where IsMatch(body[""], "^\{")
- set(attributes["tenant"], attributes["cache"]["kubernetes"]["namespace_name"])
- set(attributes["loki.tenant"], "tenant")
- delete_key(attributes, "cache")
resource:
attributes:
- key: tenantname
value: tenant
action: insert

Expected Result

tenantname resource attribute should be available.

Actual Result

No resource attributes are available..

Collector version

0.82

Environment information

Environment

OS: AWS EKS

OpenTelemetry Collector configuration

exporters:
  logging:
    verbosity: detailed
  loki:
    endpoint: http://XXXX/loki/api/v1/push
    retry_on_failure:
      enabled: true
      initial_interval: 1s
      max_elapsed_time: 120s
      max_interval: 300s
    sending_queue:
      storage: file_storage/psq
    tls:
      insecure: false
      insecure_skip_verify: true
  splunk_hec/logs:
    endpoint: https://XXXXXXXXXX/services/collector
    retry_on_failure:
      enabled: true
      initial_interval: 10s
      max_elapsed_time: 60s
      max_interval: 60s
    sending_queue:
      storage: file_storage/psq
    timeout: 30s
    tls:
      insecure: false
      insecure_skip_verify: true
    token: 95c4beb5-c1b0-4735-bcd3-310cea0c9fa8
extensions:
  health_check:
    endpoint: 0.0.0.0:13133
processors:
  memory_limiter:
    check_interval: 5s
    limit_percentage: 80
    spike_limit_percentage: 25
 
  transform:
    error_mode: ignore
    log_statements:
    - context: log
      statements:
      - set(attributes["cache"], ParseJSON(body)) where IsMatch(body[""], "^\\{")
      - set(attributes["tenant"], attributes["cache"]["kubernetes"]["namespace_name"])
      - set(attributes["loki.tenant"], "tenant")
      - delete_key(attributes, "cache")
    resource:
      attributes:
      - key: tenantname
        value: tenant 
        action: insert 
receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318
        include_metadata: true
service:
  extensions:
  - health_check
  pipelines:
    logs:
      exporters:
      - logging
      - loki
      processors:
      - transform
      - resource
      receivers:
      - otlp

Log output

Not seeing resource attribute(tenantname) which was being set in resource processor.

Additional context

No response

@sairamsadanala sairamsadanala added bug Something isn't working needs triage New item requiring triage labels Sep 18, 2023
@github-actions github-actions bot added the processor/resource Resource processor label Sep 18, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

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

@crobert-1
Copy link
Member

Hello @sairamsadanala, have you been able to find a resolution to this issue yet?

I believe from the contexts documentation in the transform processor that you should be able to use the logs context to insert a resource attribute directly. From the logs context documentation, it looks like you should have direct resource attribute access. This should work instead of using two steps to insert an attribute to the log, then moving it from the log's attributes to the log's resource attributes.

Can you try to set the resource attribute directly from within the log context?

@crobert-1 crobert-1 added question Further information is requested processor/transform Transform processor and removed bug Something isn't working labels Oct 6, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

Pinging code owners for processor/transform: @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley. See Adding Labels via Comments if you do not have permissions to add labels yourself.

@sairamsadanala
Copy link
Author

sairamsadanala commented Oct 6, 2023 via email

@TylerHelmuth
Copy link
Member

It sounds like this issue is resolved. Please ping me if you're still experiencing issues

@omri-shilton
Copy link

@sairamsadanala did you end up solving this issue? if so can you share the otel config you used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage New item requiring triage processor/resource Resource processor processor/transform Transform processor question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants