Logo

dev-resources.site

for different kinds of informations.

Tracetest Tip: Testing Span Order with Assertions

Published at
10/14/2024
Categories
tracetest
opentelemetry
testing
Author
danielbdias
Categories
3 categories in total
tracetest
open
opentelemetry
open
testing
open
Author
11 person written this
danielbdias
open
Tracetest Tip: Testing Span Order with Assertions

💡 Are you not sure how OpenTelemetry instrumentation or Trace-based testing works? Click here to see more details.

When you are instrumenting services with OpenTelemetry, you want to see traces propagated from service A to service B, and check if their communication is working as expected. For instance, in the example below, a user sends data to Service A and Service A calls Service B to augment it.

You can validate the communication flow with Tracetest using a selector in the following format.

  specs:
  - selector: span[service.name="service-a"] span[service.name="service-b"]
    assertions:
    - attr:tracetest.selected_spans.count >= 1
Enter fullscreen mode Exit fullscreen mode
  • Declaring the selector in this order means that it will only select spans from service-b that come after spans from service-a.
  • The assertion attr:tracetest.selected_spans.count >= 1 validates that at least one span exists with that criteria. For further details, visit the selector documentation.

Going back to the example above, you can write a test with a specific assertion to validate it.

type: Test
spec:
  id: FMqdxukHg
  name: Test if service B is called after service A
  trigger:
    type: http
    httpRequest:
      method: POST
      url: http://service-a:8800/sendData
      body: "{\n  \"some\": \"test\" \n}"
      headers:
      - key: Content-Type
        value: application/json
  specs:
  - selector: span[tracetest.span.type="http" service.name="service-a" name="POST /sendData"] 
              span[tracetest.span.type="http" service.name="service-b" name="POST /augmentData"]
    name: Service B was called after Service A
    assertions:
    - attr:tracetest.selected_spans.count >= 1

Enter fullscreen mode Exit fullscreen mode

When running this test with the CLI, you should have the following result.

tracetest run test -f ./tracetest/test.yaml

# It should output something like this:

# ✔ RunGroup: #uv8yYXkNg (https://app.tracetest.io/organizations/ttorg_1cbdabae7b8fd1c6/environments/ttenv_6e983cd1e9edbecf/run/uv8yYXkNg)
#  Summary: 1 passed, 0 failed, 0 pending
#   ✔ Test if service B is called after service A (https://app.tracetest.io/organizations/ttorg_1cbdabae7b8fd1c6/environments/ttenv_6e983cd1e9edbecf/test/FMqdxukHg/run/9/test) - trace id: 008075c573faf4583f42e67c9bdb4f83
#         ✔ Service B was called after Service A
Enter fullscreen mode Exit fullscreen mode

By doing this type of assertion you can validate if the dependencies are organized as intended, and even use it to validate if a trace is being propagated between services.

Here’s what it looks like in the Tracetest UI.

image.png

The example sources used in this article and setup instructions are available in the Tracetest GitHub repository.

Would you like to learn more about Tracetest and what it brings to the table? Visit the Tracetest docs and try it out by signing up today!

Also, please feel free to join our Slack Community, give Tracetest a star on GitHub, or schedule a time to chat 1:1.

opentelemetry Article's
30 articles in total
Favicon
OpenTelemetry Collector Implementation Guide: Unified Observability for Modern Systems
Favicon
Auto-Instrumentação com OpenTelemetry no EKS [Lab Session]
Favicon
InsightfulAI v0.3.0a1 Update: Railway Oriented Programming and Enhanced OpenTelemetry for Robust Pipelines
Favicon
Using OpenTelemetry with gRPC in Node.js and Express Hybrid Applications
Favicon
Enhancing Observability in Machine Learning with OpenTelemetry: InsightfulAI Update
Favicon
From Zero to Observability: Your first steps sending OpenTelemetry data to an Observability backend
Favicon
Usando stack de monitoria opensource no Kubernetes (sem Prometheus)
Favicon
Observing Spin Apps with OpenTelemetry and the .NET Aspire Dashboard
Favicon
Golang com Opentelemetry, prometheus, Grafana tempo OSS e Grafana padrão
Favicon
Monitor R Applications with an OpenTelemetry Collector
Favicon
Understanding Open telemetry and Observability for SRE
Favicon
How to publish JetBrains Rider plugin for opentelemetry/honeycomb
Favicon
Tracetest Tip: Testing Span Order with Assertions
Favicon
How to publish JetBrains Rider plugin for opentelemetry/honeycomb
Favicon
Monitoring Browser Applications with OpenTelemetry
Favicon
Instrumentação com OpenTelemetry: Zero-Code, Code-Based ou Bibliotecas Instrumentadas?
Favicon
OpenTelemetry: Traces, Métricas, Logs e Baggage
Favicon
Getting Started with OpenTelemetry
Favicon
Explorando a Observabilidade com OpenTelemetry: Propagação de Contexto e Arquiteturas Distribuídas
Favicon
Observability with ASP.NET Core using OpenTelemetry, Prometheus and Grafana
Favicon
Trace-Based Tests with GraphQL in Action!
Favicon
Wednesday Links - Edition 2024-08-07
Favicon
Implementing an Order Processing System: Part 5 - Distributed Tracing and Logging
Favicon
Tracetest Monitors: Synthetic Monitoring with OpenTelemetry and Playwright
Favicon
Unlocking Open Source Observability: OpenTelemetry, Prometheus, Thanos, Grafana, Jaeger, and OpenSearch
Favicon
Announcing Tracetest Enterprise On-Prem Solution
Favicon
OpenTelemetry with Elastic Observability
Favicon
Performans Ve Güvenilirlik Ölçekleri
Favicon
OpenTelemetry Metrics meets Azure
Favicon
OpenTelemetry Tracing on Spring Boot, Java Agent vs. Micrometer Tracing

Featured ones: