question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding getter of operationName to Span

See original GitHub issue

In my case, I need begin span in one method conditionally, and close it in another method, before close it I need check current active span is the previous one, using ThreadLocal to store span is not a graceful way, I prefer to check span name (make sure unique by application).

private static final String SPAN_NAME = "SOME_SPAN_NAME";

public void preAction() {
	boolean shouldBegin = true; // conditional
	if (shouldBegin) {
		Tracer tracer = GlobalTracer.get();
		if (tracer.activeSpan() != null) {
			Span span = tracer.buildSpan(SPAN_NAME).start();
			tracer.scopeManager().activate(span, true);
		}
	}
}

public void postAction() {
	Scope scope = GlobalTracer.get().scopeManager().active();
	if (scope != null) {
		Span span = scope.span();
		if (SPAN_NAME.equals(span.operationName())) {
			scope.close();
		}
	}
}

My workaround using BaggageItem:

private static final String SPAN_NAME = "SOME_SPAN_NAME";
private static final String BAGGAGE_NAME = "SOME_BAGGAGE_NAME";

public void preAction() {
	boolean shouldBegin = true; // conditional
	if (shouldBegin) {
		Tracer tracer = GlobalTracer.get();
		if (tracer.activeSpan() != null) {
			Span span = tracer.buildSpan(SPAN_NAME).start();
			span.setBaggageItem(BAGGAGE_NAME, "true");
			tracer.scopeManager().activate(span, true);
		}
	}
}

public void postAction() {
	Scope scope = GlobalTracer.get().scopeManager().active();
	if (scope != null) {
		Span span = scope.span();
		if ("true".equals(span.getBaggageItem(BAGGAGE_NAME))) {
			span.setBaggageItem(BAGGAGE_NAME, null); // Should we have an method removeBaggageItem ?
			scope.close();
		}
	}
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
yurishkurocommented, Aug 15, 2018

It was absolutely a conscious decision, Span API is write-only. Allowing getters on the span puts additional constraints on the implementors, and we have not yet seen a valid use case where getters would be necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NoopSpan class - opentracing_noop library - Dart API - Pub.dev
Each Span has an operation name, a human-readable string which concisely represents the work done by the Span (e.g., an RPC method name,...
Read more >
Can anyone tell how can i put getter and setter on the below ...
You want to add getter and setter but you don't have any knowledge then first go and read about them and then if...
Read more >
Spring Cloud Sleuth
Baggage values are not added spans by default, which means you can't search based on Baggage unless you opt-in. To make baggage also...
Read more >
Plugin Development Guide - Apache SkyWalking
Create ExitSpan according to the operation name (e.g. service name, uri) and the new ContextCarrier and peer address (e.g. ip+port, hostname+port).
Read more >
Operations :: 5.x Docs - Backpack for Laravel
Operations are traits that add functionality to that controller. ... Once an operation name has been set using that route, you can do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found