Skip to content

Commit

Permalink
Merge pull request #96 from yangxikun/bugfix/rokety/duplicate_trace_ids
Browse files Browse the repository at this point in the history
fix: duplicate trace ids, closes #95
  • Loading branch information
yangxikun authored Apr 14, 2024
2 parents f72ebd3 + 60ccb42 commit 93e12fd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ services:
ports:
- 80:80
jaeger:
image: jaegertracing/all-in-one
image: jaegertracing/all-in-one:1
ports:
- 26686:16686
networks:
- opentelemetry-lua
otel-collector:
image: otel/opentelemetry-collector-contrib-dev:latest
image: otel/opentelemetry-collector-contrib:0.98.0
command: [ "--config=/etc/otel-collector-config.yaml" ]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
Expand Down
24 changes: 23 additions & 1 deletion lib/opentelemetry/util.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
local _M = {}

--- Set randomseed
math.randomseed(ngx.time() + ngx.worker.pid())
local random_seed = function ()
local seed
local frandom = io.open("/dev/urandom", "rb")
if frandom then
local str = frandom:read(4)
frandom:close()
if str then
local s = 0
for i = 1, 4 do
s = 256 * s + str:byte(i)
end
seed = s
end
end

if not seed then
seed = ngx.now() * 1000 + ngx.worker.pid()
end

return seed
end

math.randomseed(random_seed())

-- performance better, but may cause clock skew
local function ngx_time_nano()
Expand Down
12 changes: 6 additions & 6 deletions otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ exporters:
endpoint: "0.0.0.0:8889"
const_labels:
label1: value1
logging:
loglevel: debug
debug:
verbosity: detailed

#zipkin:
# endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
# format: proto

jaeger:
endpoint: jaeger:14250
otlp/jaeger:
endpoint: jaeger:4317
tls:
insecure: true

Expand All @@ -37,8 +37,8 @@ service:
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging, jaeger]
exporters: [debug, otlp/jaeger]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [logging, prometheus]
exporters: [debug, prometheus]

0 comments on commit 93e12fd

Please sign in to comment.