Skip to content

Commit

Permalink
Merge pull request #40 from coroot/otel_logs
Browse files Browse the repository at this point in the history
Export container logs to OpenTelemetry collector
  • Loading branch information
def authored Sep 29, 2023
2 parents 4cdc353 + e2479d0 commit e88780b
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 82 deletions.
8 changes: 5 additions & 3 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,12 +803,14 @@ func (c *Container) runLogParser(logPath string) {
return
}

containerId := string(c.id)

if logPath != "" {
if c.logParsers[logPath] != nil {
return
}
ch := make(chan logparser.LogEntry)
parser := logparser.NewParser(ch, nil)
parser := logparser.NewParser(ch, nil, logs.OtelLogEmitter(containerId))
reader, err := logs.NewTailReader(proc.HostPath(logPath), ch)
if err != nil {
klog.Warningln(err)
Expand All @@ -827,7 +829,7 @@ func (c *Container) runLogParser(logPath string) {
klog.Warningln(err)
return
}
parser := logparser.NewParser(ch, nil)
parser := logparser.NewParser(ch, nil, logs.OtelLogEmitter(containerId))
stop := func() {
JournaldUnsubscribe(c.cgroup)
}
Expand All @@ -843,7 +845,7 @@ func (c *Container) runLogParser(logPath string) {
delete(c.logParsers, "stdout/stderr")
}
ch := make(chan logparser.LogEntry)
parser := logparser.NewParser(ch, c.metadata.logDecoder)
parser := logparser.NewParser(ch, c.metadata.logDecoder, logs.OtelLogEmitter(containerId))
reader, err := logs.NewTailReader(proc.HostPath(c.metadata.logPath), ch)
if err != nil {
klog.Warningln(err)
Expand Down
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ go 1.19

require (
cloud.google.com/go/compute/metadata v0.2.3
github.com/agoda-com/opentelemetry-logs-go v0.3.0
github.com/cilium/cilium v1.13.2
github.com/cilium/ebpf v0.11.0
github.com/containerd/cgroups v1.0.3
github.com/containerd/containerd v1.5.17
github.com/coreos/go-systemd/v22 v22.5.0
github.com/coroot/logparser v1.0.6
github.com/coroot/logparser v1.0.7
github.com/docker/docker v20.10.21+incompatible
github.com/florianl/go-conntrack v0.3.0
github.com/mdlayher/taskstats v0.0.0-20230712191918-387b3d561d14
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/prometheus/client_golang v1.14.0
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc
github.com/vishvananda/netns v0.0.4
github.com/xin053/hsperfdata v0.2.3
go.mongodb.org/mongo-driver v1.11.4
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
go.opentelemetry.io/otel/trace v1.19.0
golang.org/x/arch v0.4.0
golang.org/x/mod v0.11.0
golang.org/x/net v0.14.0
golang.org/x/sys v0.11.0
golang.org/x/sys v0.12.0
golang.org/x/time v0.3.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -37,7 +38,7 @@ require (
)

require (
cloud.google.com/go/compute v1.15.1 // indirect
cloud.google.com/go/compute v1.21.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Microsoft/hcsshim v0.8.25 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
Expand All @@ -46,7 +47,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cilium/workerpool v1.1.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect
Expand All @@ -59,7 +60,7 @@ require (
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
Expand All @@ -76,10 +77,10 @@ require (
github.com/gogo/googleapis v1.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -123,16 +124,17 @@ require (
github.com/subosito/gotenv v1.4.1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go4.org/intern v0.0.0-20210108033219-3eb7198706b2 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/grpc v1.58.2 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v0.26.4 // indirect
Expand Down
Loading

0 comments on commit e88780b

Please sign in to comment.