Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for span links #7291

Merged
merged 7 commits into from
Feb 16, 2022
Merged

Add support for span links #7291

merged 7 commits into from
Feb 16, 2022

Conversation

axw
Copy link
Member

@axw axw commented Feb 15, 2022

Motivation/summary

This PR adds support for span links to our data model, enabling a span/transaction to be associated with zero or more other spans/transactions. We use span.links and span.links.span.id regardless of whether the linked entities are spans or transactions.

The PR also adds support for capturing OpenTelemetry span links.

Checklist

How to test these changes

  1. Using an OpenTelemetry SDK, send a span with links to APM Server.
  2. Check that the trace ID and span ID of the link are stored. Any attributes or trace-state associated with the link should not be stored.
  3. Ensure the trace can be find when searching traces-apm* and querying by span.links.trace.id

Related issues

Closes #7171

@axw axw added backport-skip Skip notification from the automated backport with mergify v8.2.0 labels Feb 15, 2022
@apmmachine
Copy link
Contributor

apmmachine commented Feb 15, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-02-16T10:30:58.673+0000

  • Duration: 64 min 27 sec

Test stats 🧪

Test Results
Failed 0
Passed 5644
Skipped 19
Total 5663

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /hey-apm : Run the hey-apm benchmark.

  • /package : Generate and publish the docker images.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@axw axw marked this pull request as ready for review February 15, 2022 12:22
@axw axw requested a review from a team February 15, 2022 12:22
Copy link
Member

@felixbarny felixbarny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and easy to expand with span link attributes/labels later on.

@axw axw enabled auto-merge (squash) February 16, 2022 10:30
@axw axw merged commit 589a1cb into elastic:main Feb 16, 2022
@stuartnelson3 stuartnelson3 self-assigned this Apr 4, 2022
@stuartnelson3
Copy link
Contributor

confirmed with 4575383

  1. start kibana/elasticsearch
  2. start apm-server
  3. send traces with the following program:
package main

import (
	"context"
	"log"

	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
	"go.opentelemetry.io/otel/propagation"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"go.opentelemetry.io/otel/trace"
)

var tracer = otel.Tracer("tracer")

func main() {
	tp := initTracer()
	defer func() {
		if err := tp.Shutdown(context.Background()); err != nil {
			log.Printf("Error shutting down tracer provider: %v", err)
		}
	}()

	ctx, span := tracer.Start(context.Background(), "span")
	defer span.End()
	link := trace.LinkFromContext(ctx, attribute.Int("attr", 1))
	_, span2 := tracer.Start(ctx, "linkedSpan", trace.WithLinks(link))
	defer span2.End()
}

func initTracer() *sdktrace.TracerProvider {
	ctx := context.Background()
	// Create the OTLP exporter that
	// will receive the telemetry data
	endpoint := "localhost:8200"
	exporter, err := otlptracegrpc.New(ctx,
		otlptracegrpc.WithInsecure(),
		otlptracegrpc.WithEndpoint(endpoint),
	)
	if err != nil {
		log.Fatal(err)
	}
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSampler(sdktrace.AlwaysSample()),
		sdktrace.WithBatcher(exporter),
	)
	otel.SetTracerProvider(tp)
	otel.SetTextMapPropagator(
		propagation.NewCompositeTextMapPropagator(
			propagation.TraceContext{},
			propagation.Baggage{},
		),
	)
	return tp
}
  1. go to kibana console and verify both traces are there, and one has span links
GET traces-apm-default/_search
  1. get the span.links.trace.id and check you can query with it
GET traces-apm-default/_search
{
  "query": {
    "match": {
      "span.links.trace.id": "d1e6e6a15b5f93eb18c70f237f9ce3b3"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify test-plan test-plan-ok v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define a data model for span links
5 participants