Skip to content

Commit

Permalink
fix handling of invalid spanIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
schoren committed Nov 6, 2023
1 parent e24f6ca commit 524eb55
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 50 deletions.
90 changes: 45 additions & 45 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
version: "3.2"
services:
tracetest:
restart: unless-stopped
image: kubeshop/tracetest:${TAG:-latest}
extra_hosts:
- "host.docker.internal:host-gateway"
build:
context: .
volumes:
- type: bind
source: ./local-config/tracetest.config.yaml
target: /app/tracetest.yaml
- type: bind
source: ./local-config/tracetest.provision.yaml
target: /app/provisioning.yaml
ports:
- 11633:11633
command: --provisioning-file /app/provisioning.yaml
healthcheck:
test: ["CMD", "wget", "--spider", "localhost:11633"]
interval: 1s
timeout: 3s
retries: 60
depends_on:
postgres:
condition: service_healthy
environment:
TRACETEST_DEV: ${TRACETEST_DEV}
TRACETEST_TESTPIPELINES_TRIGGEREXECUTE_ENABLED: ${TRACETEST_TESTPIPELINES_TRIGGEREXECUTE_ENABLED}
TRACETEST_TESTPIPELINES_TRACEFETCH_ENABLED: ${TRACETEST_TESTPIPELINES_TRACEFETCH_ENABLED}
TRACETEST_DATASTOREPIPELINES_TESTCONNECTION_ENABLED: ${TRACETEST_DATASTOREPIPELINES_TESTCONNECTION_ENABLED}
# tracetest:
# restart: unless-stopped
# image: kubeshop/tracetest:${TAG:-latest}
# extra_hosts:
# - "host.docker.internal:host-gateway"
# build:
# context: .
# volumes:
# - type: bind
# source: ./local-config/tracetest.config.yaml
# target: /app/tracetest.yaml
# - type: bind
# source: ./local-config/tracetest.provision.yaml
# target: /app/provisioning.yaml
# ports:
# - 11633:11633
# command: --provisioning-file /app/provisioning.yaml
# healthcheck:
# test: ["CMD", "wget", "--spider", "localhost:11633"]
# interval: 1s
# timeout: 3s
# retries: 60
# depends_on:
# postgres:
# condition: service_healthy
# environment:
# TRACETEST_DEV: ${TRACETEST_DEV}
# TRACETEST_TESTPIPELINES_TRIGGEREXECUTE_ENABLED: ${TRACETEST_TESTPIPELINES_TRIGGEREXECUTE_ENABLED}
# TRACETEST_TESTPIPELINES_TRACEFETCH_ENABLED: ${TRACETEST_TESTPIPELINES_TRACEFETCH_ENABLED}
# TRACETEST_DATASTOREPIPELINES_TESTCONNECTION_ENABLED: ${TRACETEST_DATASTOREPIPELINES_TESTCONNECTION_ENABLED}

postgres:
image: postgres:15.2
Expand All @@ -44,18 +44,18 @@ services:
timeout: 5s
retries: 60

otel-collector:
image: otel/opentelemetry-collector-contrib:0.59.0
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "55679:55679"
- "4317:4317"
- "8888:8888"
command:
- "--config"
- "/otel-local-config.yaml"
volumes:
- ./local-config/collector.config.yaml:/otel-local-config.yaml
depends_on:
- tracetest
# otel-collector:
# image: otel/opentelemetry-collector-contrib:0.59.0
# extra_hosts:
# - "host.docker.internal:host-gateway"
# ports:
# - "55679:55679"
# - "4317:4317"
# - "8888:8888"
# command:
# - "--config"
# - "/otel-local-config.yaml"
# volumes:
# - ./local-config/collector.config.yaml:/otel-local-config.yaml
# depends_on:
# - tracetest
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require (
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.4
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569
gitlab.com/metakeule/fmtdate v1.2.2
go.opencensus.io v0.24.0
go.opentelemetry.io/collector/component v0.80.0
go.opentelemetry.io/collector/config/configcompression v0.80.0
Expand Down Expand Up @@ -172,7 +173,6 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
gitlab.com/metakeule/fmtdate v1.2.2 // indirect
go.opentelemetry.io/collector v0.80.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.80.0 // indirect
go.opentelemetry.io/collector/config/confignet v0.80.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion server/test/run_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func readRunRow(row scanner) (Run, error) {
return Run{}, fmt.Errorf("cannot parse Results: %w", err)
}

if jsonTrace != nil {
if jsonTrace != nil && string(jsonTrace) != "null" {
err = json.Unmarshal(jsonTrace, &r.Trace)
if err != nil {
return Run{}, fmt.Errorf("cannot parse Trace: %w", err)
Expand Down
19 changes: 16 additions & 3 deletions server/traces/span_entitiess.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ type encodedSpan struct {
Children []encodedSpan
}

const nilSpanID = "0000000000000000"

func (es encodedSpan) isValidID() bool {
if es.ID == nilSpanID || es.ID == "" {
return false
}
return true
}

func (s Span) IsZero() bool {
return !s.ID.IsValid()
}
Expand Down Expand Up @@ -150,9 +159,13 @@ func (s *Span) UnmarshalJSON(data []byte) error {
}

func (s *Span) decodeSpan(aux encodedSpan) error {
sid, err := trace.SpanIDFromHex(aux.ID)
if err != nil {
return fmt.Errorf("unmarshal span: %w", err)
sid := trace.SpanID{}
if aux.isValidID() {
var err error
sid, err = trace.SpanIDFromHex(aux.ID)
if err != nil {
return fmt.Errorf("unmarshal span: %w", err)
}
}

children, err := decodeChildren(s, aux.Children, getCache())
Expand Down

0 comments on commit 524eb55

Please sign in to comment.