{{- define "statefulset.processor.transform.use_grafana_metric_names" -}}
otelcol.processor.transform "use_grafana_metric_names" {
  // https://grafana.com/docs/alloy/latest/reference/components/otelcol.processor.transform/
  error_mode = "ignore"

  metric_statements {
    context    = "metric"
    statements = [
      "set(name, \"traces.spanmetrics.latency\") where name == \"traces.spanmetrics.duration\"",
      "set(name, \"traces.spanmetrics.calls.total\") where name == \"traces.spanmetrics.calls\"",
    ]
  }

  output {
    metrics = [otelcol.processor.batch.default.input]
  }
}

{{ end }}

{{- define "statefulset.processor.transform.drop_unneeded_resource_attributes"}}
otelcol.processor.transform "drop_unneeded_resource_attributes" {
    // https://grafana.com/docs/alloy/latest/reference/components/otelcol.processor.transform/
    error_mode = "ignore"

    trace_statements {
        context = "resource"
        statements = [
            "delete_key(attributes, \"k8s.pod.start_time\")",
            "delete_key(attributes, \"os.description\")",
            "delete_key(attributes, \"os.type\")",
            "delete_key(attributes, \"process.command_args\")",
            "delete_key(attributes, \"process.executable.path\")",
            "delete_key(attributes, \"process.pid\")",
            "delete_key(attributes, \"process.runtime.description\")",
            "delete_key(attributes, \"process.runtime.name\")",
            "delete_key(attributes, \"process.runtime.version\")",
        ]
    }

    output {
        traces = [otelcol.connector.spanmetrics.default.input]
    }
}

{{ end  }}
