{"id":17462885,"url":"https://github.com/mralias/otlpr","last_synced_at":"2025-04-19T18:51:45.604Z","repository":{"id":65615054,"uuid":"564944998","full_name":"MrAlias/otlpr","owner":"MrAlias","description":"A logr implementation backed by OTLP","archived":false,"fork":false,"pushed_at":"2024-04-08T14:39:54.000Z","size":179,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-08T18:10:41.752Z","etag":null,"topics":["go","golang","logger","logging","logr","opentelemetry","opentelemetry-go","otel","otlp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrAlias.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-11-11T22:04:58.000Z","updated_at":"2024-04-14T16:51:56.802Z","dependencies_parsed_at":"2023-02-18T09:30:31.523Z","dependency_job_id":"4f3c3f91-7166-4f1c-9891-bf510a83538e","html_url":"https://github.com/MrAlias/otlpr","commit_stats":{"total_commits":44,"total_committers":3,"mean_commits":"14.666666666666666","dds":"0.40909090909090906","last_synced_commit":"7c742bc058ca64a5c60f98baf8c99e6bf4b8c691"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrAlias%2Fotlpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrAlias%2Fotlpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrAlias%2Fotlpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrAlias%2Fotlpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrAlias","download_url":"https://codeload.github.com/MrAlias/otlpr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240405884,"owners_count":19796258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","logger","logging","logr","opentelemetry","opentelemetry-go","otel","otlp"],"created_at":"2024-10-18T09:10:26.847Z","updated_at":"2025-03-02T21:31:26.941Z","avatar_url":"https://github.com/MrAlias.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# otlpr\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/MrAlias/otlpr.svg)](https://pkg.go.dev/github.com/MrAlias/otlpr)\n\nThis repository provides a [`logr.Logger`] that exports recorded messages as [OpenTelemetry logs] to an [OTLP] receiving endpoint.\n\n:construction: This repository is a work in progress and not production ready.\n\n## Getting Started\n\nA working gRPC connection to an OTLP receiving endpoint is needed to setup the logger.\n\n```go\nconn, _ := grpc.NewClient(otlpTarget)\n```\n\nCreate a [`logr.Logger`] with this connection.\n\n```go\nlogger := otlpr.New(conn)\n```\n\nSee the [example] for a working example application.\n\n## Batching\n\nBy default the logger will batch the log messages as they are received.\nIt will wait to batch `2048` messages before exporting.\n\nA `Batcher` can be used to change this behavior.\n\n```go\nopts := otlpr.Options{\n\tBatcher: otlpr.Batcher{\n\t\t// Only queue at most 100 messages.\n\t\tMessages: 100,\n\t\t// Only wait 3 seconds for the queue to fill.\n\t\tTimeout: 3 * time.Second,\n\t},\n}\nlogger := otlpr.NewWithOptions(conn, opts)\n```\n\n### Max messages in export\n\nThe `Batcher` can be configured to limit the number of messages it sends for\neach export with the `ExportN` setting.\n\n```go\nopts := otlpr.Options{\n\tBatcher: otlpr.Batcher{\n\t\t// Only send at most 100 messages per export.\n\t\tExportN: 100,\n\t},\n}\nlogger := otlpr.NewWithOptions(conn, opts)\n```\n\n## Annotating Span Context\n\nOTLP is able to associate span context with log messages.\nUse the `WithContext` function to associate a `context.Context` that contains an active span with all logs the logger creates.\n\n```go\nlogger = otlpr.WithContext(logger, ctx)\n```\n\nThe function can also be used to clear any span context from the logger.\n\n```go\nlogger = otlpr.WithContext(logger, context.Background())\n```\n\n[`logr.Logger`]: https://pkg.go.dev/github.com/go-logr/logr#Logger\n[example]: ./example/\n\n## Adding a Resource\n\nThe system a log message is produced in can be described with a [`Resource`].\nUse the `WithResource` function to include this information with the exported OTLP data.\n\n```go\nlogger = otlpr.WithResource(logger, resource)\n```\n\nThe function can also be used to clear any resource from the logger.\n\n```go\nlogger = otlpr.WithResource(logger, nil)\n```\n\n## Adding Scope\n\nThe portion of a system a log message is produced in can be described with [`Scope`].\nUse the `WithScope` function to include this information with the exported OTLP data.\n\n```go\nlogger = otlpr.WithScope(logger, resource)\n```\n\nThe function can also be used to clear any scope from the logger.\n\n```go\nlogger = otlpr.WithScope(logger, instrumentation.Scope{})\n```\n\n[`logr.Logger`]: https://pkg.go.dev/github.com/go-logr/logr#Logger\n[OpenTelemetry logs]: https://opentelemetry.io/docs/reference/specification/logs/data-model/\n[OTLP]: https://opentelemetry.io/docs/reference/specification/protocol/\n[example]: ./example/\n[`Resource`]: https://pkg.go.dev/go.opentelemetry.io/otel/sdk/resource#Resource\n[`Scope`]: https://pkg.go.dev/go.opentelemetry.io/otel/sdk/instrumentation#Scope\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmralias%2Fotlpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmralias%2Fotlpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmralias%2Fotlpr/lists"}