{{ define "agent.config.tracesService" }}
{{- with .Values.externalServices.tempo }}
// Tempo
local.file "tempo_host" {
  filename  = "/etc/grafana-agent-credentials/tempo_host"
}
{{ if .basicAuth.username }}
local.file "tempo_username" {
  filename  = "/etc/grafana-agent-credentials/tempo_username"
}
{{- end }}
{{ if .basicAuth.password }}
local.file "tempo_password" {
  filename  = "/etc/grafana-agent-credentials/tempo_password"
  is_secret = true
}
{{- end }}
{{ if .tenantId }}
local.file "tempo_tenantid" {
  filename  = "/etc/grafana-agent-credentials/tempo_tenantId"
}
{{- end }}
{{ if or (.basicAuth.username) (.basicAuth.password) }}
otelcol.auth.basic "tempo" {
  {{ if .basicAuth.username }}username = local.file.tempo_username.content{{ end }}
  {{ if .basicAuth.password }}password = local.file.tempo_password.content{{ end }}
}
{{- end }}
{{ if eq .protocol "otlp" }}
otelcol.exporter.otlp "tempo" {
{{- else if eq .protocol "otlphttp" }}
otelcol.exporter.otlphttp "tempo" {
{{- end }}
  client {
    endpoint = nonsensitive(local.file.tempo_host.content)
{{ if or (.basicAuth.username) (.basicAuth.password) }}
    auth = otelcol.auth.basic.tempo.handler
{{- end }}
{{- if .tenantId }}
    headers = { "X-Scope-OrgID" = local.file.tempo_tenantid.content }
{{- end }}
{{- if .tlsOptions }}
    tls {
{{ .tlsOptions | indent 6 }}
    }
{{- else if .tls }}
    tls {
    {{- range $k, $v := .tls }}
      {{ $k }} = {{ $v | toJson }}
    {{- end }}
    }
{{- end }}
  }
}
{{- end }}
{{ end }}
