ConfigFromDockerContext inspects extra metadata included as part of the specified Docker context to try and extract a valid OTLP client configuration.
(st store.Store, name string)
| 79 | // ConfigFromDockerContext inspects extra metadata included as part of the |
| 80 | // specified Docker context to try and extract a valid OTLP client configuration. |
| 81 | func ConfigFromDockerContext(st store.Store, name string) (OTLPConfig, error) { |
| 82 | meta, err := st.GetMetadata(name) |
| 83 | if err != nil { |
| 84 | return OTLPConfig{}, err |
| 85 | } |
| 86 | |
| 87 | var otelCfg any |
| 88 | switch m := meta.Metadata.(type) { |
| 89 | case command.DockerContext: |
| 90 | otelCfg = m.AdditionalFields[otelConfigFieldName] |
| 91 | case map[string]any: |
| 92 | otelCfg = m[otelConfigFieldName] |
| 93 | } |
| 94 | if otelCfg == nil { |
| 95 | return OTLPConfig{}, nil |
| 96 | } |
| 97 | |
| 98 | otelMap, ok := otelCfg.(map[string]any) |
| 99 | if !ok { |
| 100 | return OTLPConfig{}, fmt.Errorf( |
| 101 | "unexpected type for field %q: %T (expected: %T)", |
| 102 | otelConfigFieldName, |
| 103 | otelCfg, |
| 104 | otelMap, |
| 105 | ) |
| 106 | } |
| 107 | |
| 108 | // keys from https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/ |
| 109 | cfg := OTLPConfig{ |
| 110 | Endpoint: valueOrDefault[string](otelMap, "OTEL_EXPORTER_OTLP_ENDPOINT"), |
| 111 | } |
| 112 | return cfg, nil |
| 113 | } |
| 114 | |
| 115 | // valueOrDefault returns the type-cast value at the specified key in the map |
| 116 | // if present and the correct type; otherwise, it returns the default value for |
no outgoing calls