2
0

otel.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. -- For OpenTelemetry APM protocol over HTTP, see https://github.com/winlinvip/otel-wireshark-plugin
  2. --
  3. -- To apply this wireshark plugin:
  4. -- mkdir -p ~/.local/lib/wireshark/plugins
  5. -- ln -sf $(pwd)/otel.lua ~/.local/lib/wireshark/plugins/otel.lua
  6. -- Download proto files for otel:
  7. -- git clone https://github.com/open-telemetry/opentelemetry-proto.git
  8. -- Setup Wireshark `Protobuf search paths` to load the proto files at `Preferences > Protocols > Protobuf`:
  9. -- /home/winlin/git/opentelemetry-proto
  10. -- /home/winlin/git/otel-wireshark-plugin/cls
  11. -- Start capture or parsing file.
  12. do
  13. function string_starts_with(str, start)
  14. return str ~= nil and str:sub(1, #start) == start
  15. end
  16. -- See https://gitlab.com/wireshark/wireshark/-/wikis/Protobuf#write-your-own-protobuf-udp-or-tcp-dissectors
  17. local protobuf_dissector = Dissector.get("protobuf")
  18. -- Only parsing Protobuf over HTTP, with http uri.
  19. local f_http_uri = Field.new("http.request.uri")
  20. local otel_proto = Proto("otel_proto", "Extra analysis of the HTTP protocol");
  21. function otel_proto.dissector(tvb, pinfo, tree)
  22. local http_uri = f_http_uri()
  23. if http_uri == nil then return end
  24. -- See https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/trace/v1/trace_service.proto
  25. if string_starts_with(http_uri.value, "/v1/traces") then
  26. pinfo.private["pb_msg_type"] = "message," .. "opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest"
  27. pcall(Dissector.call, protobuf_dissector, tvb, pinfo, tree)
  28. end
  29. -- See https://cloud.tencent.com/document/api/614/16873
  30. if string_starts_with(http_uri.value, "/structuredlog") then
  31. pinfo.private["pb_msg_type"] = "message," .. "cls.LogGroupList"
  32. pcall(Dissector.call, protobuf_dissector, tvb, pinfo, tree)
  33. end
  34. end
  35. local tbl = DissectorTable.get("media_type")
  36. tbl:add("application/x-protobuf", otel_proto)
  37. print("Add application/x-protobuf dissector", otel_proto)
  38. end