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

Collector return "invalid length for ID" for trace reporting #3195

Closed
jacky15 opened this issue May 17, 2021 · 9 comments
Closed

Collector return "invalid length for ID" for trace reporting #3195

jacky15 opened this issue May 17, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@jacky15
Copy link

jacky15 commented May 17, 2021

Describe the bug
I am using opentelemetry-collector with otlphttp exporter. But when data report to the collector, it return HTTP status code 400 with the message "invalid length for ID"

Steps to reproduce
Here is the tcp traffic

POST /v1/traces HTTP/1.1
Host: 10.0.1.21:4317
User-Agent: Go-http-client/1.1
Content-Length: 20316
Content-Type: application/json
Accept-Encoding: gzip

{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"unknown_service:unify-query"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"0.19.0"}}]},"instrumentationLibrarySpans":[{"instrumentationLibrary":{"name":"bk-monitorv3/unify-query"},"spans":[{"traceId":"cgXI6uihz643E6Zqq7Nl4w==","spanId":"+iPdFTeJDX8=","name":"/metrics","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1621253293188761633","endTimeUnixNano":"1621253293190601010","status":{"code":"STATUS_CODE_OK"}},{"traceId":"tXrmFgvi148s6EsroJ1S1A==","spanId":"zIqhNylUXuk=","name":"/metrics","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1621254568188753964","endTimeUnixNano":"1621254568189747171","status":{"code":"STATUS_CODE_OK"}},{"traceId":"Q2sKzOrO09THC8n5rb8V5Q==","spanId":"x6GjCl4l8t8=","name":"/metrics","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1621254583188746771","endTimeUnixNano":"1621254583189715582","status":{"code":"STATUS_CODE_OK"}}]}]}]}

HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Mon, 17 May 2021 12:29:56 GMT
Content-Length: 73

{
  "code": 3,
  "message": "invalid length for ID",
  "details": [
  ]
}

What did you expect to see?
Report success.

What did you see instead?
Report failed with 400 status code

What version did you use?
Version: c1e3d47

What config did you use?

receivers:
  otlp:
    protocols:
      http:
        endpoint: "0.0.0.0:4317"
processors:
  batch:
extensions:
  health_check: {}
exporters:
  zipkin:
    endpoint: "http://10.0.0.1:9411/api/v2/spans"
    format: proto
  logging:
    loglevel: debug
extensions:
  health_check:
  pprof:
    endpoint: :1888
  zpages:
    endpoint: :55679
service:
  extensions: [pprof, zpages, health_check]
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [zipkin]
      processors: [batch]

Environment
OS: centos-release-7-8.2003.0.el7.centos.x86_64
Compiler(if manually compiled): go version go1.14 linux/amd64

@jacky15 jacky15 added the bug Something isn't working label May 17, 2021
@bogdandrutu
Copy link
Member

the trace/span ID need to be hex encoded not base64 cgXI6uihz643E6Zqq7Nl4w==. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request

@bryanuribe
Copy link
Contributor

Do you need someone to work this? If so, would I be able to pick this up?
cc: @alolita

@jacky15
Copy link
Author

jacky15 commented May 18, 2021

the trace/span ID need to be hex encoded not base64 cgXI6uihz643E6Zqq7Nl4w==. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request

According to this, Is this a bug of the http exporter?

@bogdandrutu
Copy link
Member

What http exporter do you use? Seems like a bug there if they send JSON data (which seems to be the case based on the payload)

@jacky15
Copy link
Author

jacky15 commented May 19, 2021

I am using the exporter from "go.opentelemetry.io/otel/exporters/otlp/otlphttp"
Here is the code used to init the exporter

func (s *Service) Start(ctx context.Context) {
	var err error

	if !viper.GetBool(EnableConfigPath) {
		log.SugaredLogger.Infof("trace is disable, no exporter will start.")
		return
	}

	s.driverOps = []otlphttp.Option{
		otlphttp.WithEndpoint(strings.Join([]string{reportHost, reportPort}, ":")),
		otlphttp.WithInsecure(),
		otlphttp.WithMarshal(otlphttp.MarshalJSON),
	}
	s.traceDriver = otlphttp.NewDriver(s.driverOps...)

	if s.Exporter, err = otlp.NewExporter(ctx, s.traceDriver); err != nil {
		log.SugaredLogger.Errorf("failed to config tracing exporter for err->[%s]", err)
		return
	}
	s.wg.Add(1)

	bsp := sdktrace.NewBatchSpanProcessor(s.Exporter)
	tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(bsp))
	otel.SetTracerProvider(tp)
	propagator := propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})
	otel.SetTextMapPropagator(propagator)

	s.ctx, s.cancelFunc = context.WithCancel(ctx)
	log.SugaredLogger.Infof("trace exporter start success.")
}

@bogdandrutu
Copy link
Member

Oh, so you are using golang sdk. Just change for the moment:

otlphttp.WithMarshal(otlphttp.MarshalJSON) to otlphttp.WithMarshal(otlphttp.MarshalProto)

@bogdandrutu
Copy link
Member

Created a bug in the golang SDK, closing this since we implement the specs.

@jacky15
Copy link
Author

jacky15 commented May 24, 2021

It works after change the code to otlphttp.WithMarshal(otlphttp.MarshalProto)
Thanks a lot!

@utezduyar
Copy link
Contributor

Actually I think the marshaled output is correct, base64 according to the spec: https://github.com/open-telemetry/oteps/blob/main/text/0122-otlp-http-json.md#json-mapping
Use proto3 standard defined [JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json) for mapping between protobuf and json. trace_id and span_id is base64 encoded in OTLP/HTTP+JSON, not hex.
There is a mismatch between the spec and the collector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants