Last active
September 5, 2022 14:52
-
-
Save winlinvip/298bcfbb59865c471a475b0550e49bb3 to your computer and use it in GitHub Desktop.
Wireshark dissector for parsing Protobuf for APM over HTTP1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- To apply this wireshark plugin: | |
-- mkdir -p ~/.local/lib/wireshark/plugins | |
-- ln -sf $(pwd)/otel.lua ~/.local/lib/wireshark/plugins/otel.lua | |
-- Download proto files for otel: | |
-- git clone https://github.com/open-telemetry/opentelemetry-proto.git | |
-- Setup Wireshark `Protobuf search paths` to load the proto files at `Preferences > Protocols > Protobuf`: | |
-- ~/git/opentelemetry-proto | |
-- ~/git/srs/trunk/research/proto | |
-- Start capture or parsing file. | |
do | |
function string_starts_with(str, start) | |
return str ~= nil and str:sub(1, #start) == start | |
end | |
-- See https://gitlab.com/wireshark/wireshark/-/wikis/Protobuf#write-your-own-protobuf-udp-or-tcp-dissectors | |
local protobuf_dissector = Dissector.get("protobuf") | |
-- Only parsing Protobuf over HTTP, with http uri. | |
local f_http_uri = Field.new("http.request.uri") | |
local otel_proto = Proto("otel_proto", "Extra analysis of the HTTP protocol"); | |
function otel_proto.dissector(tvb, pinfo, tree) | |
local http_uri = f_http_uri() | |
if http_uri == nil then return end | |
-- See https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/trace/v1/trace_service.proto | |
if string_starts_with(http_uri.value, "/v1/traces") then | |
pinfo.private["pb_msg_type"] = "message," .. "opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest" | |
pcall(Dissector.call, protobuf_dissector, tvb, pinfo, tree) | |
end | |
-- See https://cloud.tencent.com/document/api/614/16873 | |
if string_starts_with(http_uri.value, "/structuredlog") then | |
pinfo.private["pb_msg_type"] = "message," .. "cls.LogGroupList" | |
pcall(Dissector.call, protobuf_dissector, tvb, pinfo, tree) | |
end | |
end | |
local tbl = DissectorTable.get("media_type") | |
tbl:add("application/x-protobuf", otel_proto) | |
print("Add application/x-protobuf dissector", otel_proto) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
APM over HTTP1, please see otlptracehttp
To upload to APM: