Repository: zeromicro/go-zero
Pull request #3271 (2023-05-21 10:31:26)

feat: add OtlpHttpPath config support for ZincObserve Telemetry
fix: https://github.com/zeromicro/go-zero/issues/3270

usage:

```yaml
Telemetry:
  Name: api-api
  Endpoint: 172.26.246.157:5080
  Sampler: 1.0
  Batcher: otlphttp
  OtlpHeaders:
    Authorization: "Basic balabala"
  OtlpHttpPath: /api/default/traces

```

<img width="880" alt="image" src="https://github.com/zeromicro/go-zero/assets/5897356/d3b27d7d-2187-4f5c-a5df-7bc9e5467ec0">


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3271?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3271](https://app.codecov.io/gh/zeromicro/go-zero/pull/3271?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (c982b5e) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/a9aac7e4200ab39885200fcec48b33add425a0b8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (a9aac7e) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.


| [Impacted Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/3271?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/trace/agent.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3271?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS90cmFjZS9hZ2VudC5nbw==) | `93.82% <100.00%> (+0.23%)` | :arrow_up: |

... and [2 files with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3271/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/trace/agent.go b/core/trace/agent.go
index 9b293e45..5bae9f6d 100644
--- a/core/trace/agent.go
+++ b/core/trace/agent.go
@@ -91,6 +91,9 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
 		if len(c.OtlpHeaders) > 0 {
 			opts = append(opts, otlptracehttp.WithHeaders(c.OtlpHeaders))
 		}
+		if len(c.OtlpHttpPath) > 0 {
+			opts = append(opts, otlptracehttp.WithURLPath(c.OtlpHttpPath))
+		}
 		return otlptracehttp.New(
 			context.Background(),
 			opts...,
diff --git a/core/trace/config.go b/core/trace/config.go
index 9423f97c..b59af555 100644
--- a/core/trace/config.go
+++ b/core/trace/config.go
@@ -13,4 +13,8 @@ type Config struct {
 	// For example:
 	//  uptrace-dsn: 'http://project2_secret_token@localhost:14317/2'
 	OtlpHeaders map[string]string `json:",optional"`
+	// OtlpHttpPath represents the path for OTLP HTTP transport.
+	// For example
+	// /v1/traces
+	OtlpHttpPath string            `json:",optional"`
 }


Test patch:
diff --git a/core/trace/agent_test.go b/core/trace/agent_test.go
index a3871a42..cbced387 100644
--- a/core/trace/agent_test.go
+++ b/core/trace/agent_test.go
@@ -50,6 +50,7 @@ func TestStartAgent(t *testing.T) {
 		OtlpHeaders: map[string]string{
 			"uptrace-dsn": "http://project2_secret_token@localhost:14318/2",
 		},
+		OtlpHttpPath: "/v1/traces",
 	}
 	c7 := Config{
 		Name:     "UDP",