Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set otel export url #184

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/infra/open_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/moby/moby/client"
"log"
"os"
"path"
"path/filepath"
Expand All @@ -23,6 +24,7 @@ const sslCertificates = "/etc/ssl/certs/ca-certificates.crt"
type Collector struct {
cli *client.Client
containerID string
url string
}

// NewCollector starts the OpenTelemetry collector container.
Expand Down Expand Up @@ -87,6 +89,17 @@ func NewCollector(ctx context.Context, cli *client.Client, net *Networks, params
return nil, fmt.Errorf("failed to start collector container: %w", err)
}

containerInfo, err := cli.ContainerInspect(ctx, collector.containerID)
if err != nil {
return nil, fmt.Errorf("failed to inspect collector container: %w", err)
}
if net != nil {
collector.url = fmt.Sprintf("http://%s:4318", containerInfo.NetworkSettings.Networks[net.noInternetName].IPAddress)
} else {
// This should only happen during testing, adding a warning in case
log.Println("Warning: no-internet network not found")
}

return collector, nil

}
Expand Down
5 changes: 3 additions & 2 deletions internal/infra/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,16 @@ func runContainers(ctx context.Context, params RunParams, api *server.API) error
go prox.TailLogs(ctx, cli)
}

var collector *Collector
if params.CollectorConfigPath != "" {
collector, err := NewCollector(ctx, cli, networks, &params, prox)
collector, err = NewCollector(ctx, cli, networks, &params, prox)
if err != nil {
return err
}
defer collector.Close()
}

updater, err := NewUpdater(ctx, cli, networks, &params, prox)
updater, err := NewUpdater(ctx, cli, networks, &params, prox, collector)
if err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions internal/infra/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
)

// NewUpdater starts the update container interactively running /bin/sh, so it does not stop.
func NewUpdater(ctx context.Context, cli *client.Client, net *Networks, params *RunParams, prox *Proxy) (*Updater, error) {
func NewUpdater(ctx context.Context, cli *client.Client, net *Networks, params *RunParams, prox *Proxy, collector *Collector) (*Updater, error) {
containerCfg := &container.Config{
User: dependabot,
Image: params.UpdaterImage,
Expand All @@ -55,7 +55,12 @@ func NewUpdater(ctx context.Context, cli *client.Client, net *Networks, params *
}

if params.CollectorConfigPath != "" {
containerCfg.Env = append(containerCfg.Env, "OTEL_ENABLED=true")
containerCfg.Env = append(
containerCfg.Env,
[]string{
"OTEL_ENABLED=true",
fmt.Sprintf("OTEL_EXPORTER_OTLP_ENDPOINT=%s", collector.url),
}...)
}

hostCfg := &container.HostConfig{}
Expand Down
Loading