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

Export logs as json to Google Cloud Logging #36845

Open
ashish-b-choudhary-db opened this issue Dec 16, 2024 · 5 comments
Open

Export logs as json to Google Cloud Logging #36845

ashish-b-choudhary-db opened this issue Dec 16, 2024 · 5 comments
Assignees
Labels

Comments

@ashish-b-choudhary-db
Copy link

Component(s)

exporter/googlecloud

Is your feature request related to a problem? Please describe.

Currently the Google Cloud exporter sends the logs in an unstructured format under textPayload.

Describe the solution you'd like

Provide option to send the logs in a structured manner as json with the right mappings.

Describe alternatives you've considered

Going to try and look into transforming it ourselves

Additional context

No response

@ashish-b-choudhary-db ashish-b-choudhary-db added enhancement New feature or request needs triage New item requiring triage labels Dec 16, 2024
Copy link
Contributor

Pinging code owners:

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

@dashpole
Copy link
Contributor

The logging exporter will attempt to export json-structured logs if the value type is Map or Bytes, and is able to be converted to json: https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/8da0f42dab085c916987891419461d583a2aa96e/exporter/collector/logs.go#L503

Let me know if you need help formatting logs in that way.

@dashpole dashpole self-assigned this Dec 16, 2024
@dashpole dashpole removed the needs triage New item requiring triage label Dec 16, 2024
@ashish-b-choudhary-db
Copy link
Author

ashish-b-choudhary-db commented Dec 16, 2024

Yes please, would you have any suggestions on how to achieve the same.
Currently we're trying to use the https://opentelemetry.io/docs/zero-code/java/spring-boot-starter/ to send logs to a collector and then to Cloud Logging.
The native logs are structured while these logs are currently unstructured, we're trying to make the format same to have hybrid logs.

But since the exporter does support the same, that gives me more to work with. Spring Boot supports structured logging out of the box now. More to explore.

@dashpole
Copy link
Contributor

You will want to use the transform processor. You should be able to do something like this:

transform:
  log_statements:
    - context: log
      statements:
      - set(attributes["body"], body)
      - set(body, attributes)

That moves the existing body into attributes, and then moves all attributes (which is a map) into the body

@dashpole
Copy link
Contributor

Ah, you probably need to delete attributes as well (since they are now moved to the body. I updated the example above to use keep_keys to remove all keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants