{"id":14046750,"url":"https://github.com/SigNoz/zap_otlp","last_synced_at":"2025-07-27T20:32:47.458Z","repository":{"id":162978491,"uuid":"637755374","full_name":"SigNoz/zap_otlp","owner":"SigNoz","description":"Zap Logger with OpenTelemetry support","archived":false,"fork":false,"pushed_at":"2024-08-08T13:20:59.000Z","size":97,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-30T17:54:44.887Z","etag":null,"topics":["golang","logging","zap"],"latest_commit_sha":null,"homepage":"https://signoz.io","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SigNoz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-08T10:44:49.000Z","updated_at":"2024-10-01T21:10:45.000Z","dependencies_parsed_at":"2023-09-26T15:29:23.111Z","dependency_job_id":"4a82e461-a070-4ebf-9595-53f0797036ba","html_url":"https://github.com/SigNoz/zap_otlp","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SigNoz%2Fzap_otlp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SigNoz%2Fzap_otlp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SigNoz%2Fzap_otlp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SigNoz%2Fzap_otlp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SigNoz","download_url":"https://codeload.github.com/SigNoz/zap_otlp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227834702,"owners_count":17826812,"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":["golang","logging","zap"],"created_at":"2024-08-12T10:01:19.350Z","updated_at":"2024-12-03T01:30:59.631Z","avatar_url":"https://github.com/SigNoz.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Zap OTLP\n\ninspired from https://github.com/MrAlias/otlpr\n\nThis plugin helps you send logs from [zap](https://github.com/uber-go/zap) logger to a OTLP endpoint in your Go application.\n\n## Getting Started\n* Create two encoders. One for console and the other for OTLP.\n    ```\n    config := zap.NewProductionEncoderConfig()\n  \totlpEncoder := zapotlpencoder.NewOTLPEncoder(config)\n\tconsoleEncoder := zapcore.NewConsoleEncoder(config)\n    ```\n* Initialize the OTLP sync to send data to OTLP endpoint\n    ```\n    var targetPtr = flag.String(\"target\", \"127.0.0.1:4317\", \"OTLP target\")\n    var grpcInsecure = os.Getenv(\"OTEL_EXPORTER_OTLP_INSECURE\")\n\n    ...\n\n    var secureOption grpc.DialOption\n\tif strings.ToLower(grpcInsecure) == \"false\" || grpcInsecure == \"0\" || strings.ToLower(grpcInsecure) == \"f\" {\n\t\tsecureOption = grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, \"\"))\n\t} else {\n\t\tsecureOption = grpc.WithTransportCredentials(insecure.NewCredentials())\n\t}\n    conn, err := grpc.DialContext(ctx, *targetPtr, grpc.WithBlock(), secureOption, grpc.WithTimeout(time.Duration(5)*time.Second))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n    otlpSync := zapotlpsync.NewOtlpSyncer(conn, zapotlpsync.Options{\n\t\tBatchSize:      100,\n\t\tResourceSchema: semconv.SchemaURL,\n\t\tResource:       resource.NewWithAttributes(\n            semconv.SchemaURL,\n            semconv.ServiceNameKey.String(\"example application\"),\n        ),\n\t})\n    ```\n* Configure zap to use the encoders and sync.\n    ```\n    core := zapcore.NewTee(\n        zapcore.NewCore(consoleEncoder, os.Stdout, defaultLogLevel),\n        zapcore.NewCore(otlpEncoder, otlpSync, defaultLogLevel),\n    )\n    logger := zap.New(core, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel))\n    ```\nSee the [example](./example/main.go) for a working example application.\n\n## Configurations\n1) Batching\n   The default batch size is 100, you can change the batch size in `zapotlpsync.Options`\n    ```\n    zapotlpsync.Options{\n        BatchSize:      \u003cbatch size\u003e,\n        .....\n    ```\n2) BatchInterval:\n    Time duration after which a batch will be sent regardless of size. Default is 5seconds. You can \n    change it in `zapotlpsync.Options`\n    ```\n    zapotlpsync.Options{\n\t\tBatchInterval:      \u003cinterval_in_secs\u003e,\n        .....\n    ```\n\n## Send Trace Details\n* The trace details are not populated automatically. You will have to add it in your log lines by passing the context to `zapotlp.SpanCtx()`\n  ```\n  a.logger.Named(\"test_logger\").Info(\"trace_test\", zapotlp.SpanCtx(ctx))\n  ```\n\n## To send data to signoz cloud\n\nSet these environment variables\n\n```\nOTEL_EXPORTER_OTLP_HEADERS=signoz-access-token=\u003cSIGNOZ_INGESTION_KEY\u003e\nOTEL_EXPORTER_OTLP_INSECURE=false\n```\n\nReplace `\u003cSIGNOZ_INGESTION_KEY\u003e` with your ingestion token\n\ntarget = ingest.{region}.signoz.cloud:443\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSigNoz%2Fzap_otlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSigNoz%2Fzap_otlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSigNoz%2Fzap_otlp/lists"}