apiVersion: "config.istio.io/v1alpha2"
kind: stackdriver
metadata:
  name: tracing-handler
  namespace: istio-system
spec:
  push_interval: 10s
  trace:
    sample_probability: 0.1
---
#################################################
############## Tracing Config ###################
#################################################
apiVersion: "config.istio.io/v1alpha2"
kind: tracespan
metadata:
  name: stackdriver-span
  namespace: istio-system
spec:
  traceId: request.headers["x-b3-traceid"]
  spanId: request.headers["x-b3-spanid"] | ""
  parentSpanId: request.headers["x-b3-parentspanid"] | ""
  spanName: destination.service.host | destination.service.name | destination.workload.name | "unknown"
  startTime: request.time
  endTime: response.time
  clientSpan: (context.reporter.kind | "inbound") == "outbound"
  rewriteClientSpanId: "true"
  spanTags:
    destination_service_name: destination.service.name | "unknown"
    destination_service_namespace: destination.service.namespace | "unknown"
    destination_port: destination.port | 0
    request_operation: conditional((context.protocol | "unknown") == "grpc", request.path | "unknown", request.method | "unknown")
    request_protocol: context.protocol | "unknown"
    api_version: api.version | "unknown"
    api_name: api.service | "unknown"
    response_code: response.code | 0
    service_authentication_policy: conditional((context.reporter.kind | "inbound") == "outbound", "unknown", conditional(connection.mtls | false, "mutual_tls", "none"))
    source_workload_namespace: source.workload.namespace | "unknown"
    source_workload_name: source.workload.name | "unknown"
    source_owner: source.owner | "unknown"
    destination_workload_namespace: destination.workload.namespace | "unknown"
    destination_workload_name: destination.workload.name | "unknown"
    destination_owner: destination.owner | "unknown"
    http_url: request.path | ""
    request_size: request.size | 0
    response_size: response.size | 0
    source_ip: source.ip | ip("0.0.0.0")
---
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
  name: stackdriver-tracing-rule
  namespace: istio-system
spec:
  match: context.protocol == "http" || context.protocol == "grpc"  # If omitted match is true.
  actions:
  - handler: tracing-handler.stackdriver.istio-system
    instances:
    - stackdriver-span.tracespan.istio-system