title: ASP.NET Core Web API and Jaeger - Can I change the top level Span name?
body: <p>I am doing some prototyping of Jaeger Tracing for an ASP.NET Core Web API and I am able to get it working using the <a href="https://www.jaegertracing.io/docs/1.19/getting-started/" rel="nofollow noreferrer">All in One instance of Jaeger described in the Getting Started documentation</a> and the following code in my <code>Startup.ConfigureServices()</code> method:</p>
  <pre><code>services.AddOpenTracing();
  
  services.AddSingleton&lt;ITracer&gt;(serviceProvider =&gt;
  {
      string serviceName = serviceProvider.GetRequiredService&lt;IWebHostEnvironment&gt;().ApplicationName;
  
      ILoggerFactory loggerFactory = serviceProvider.GetRequiredService&lt;ILoggerFactory&gt;();
  
      // Using the UDP sender
      Jaeger.Senders.Thrift.UdpSender udpSender = new Jaeger.Senders.Thrift.UdpSender();
  
      var reporter = new RemoteReporter.Builder().WithLoggerFactory(loggerFactory).WithSender(udpSender).Build();
      var sampler = new ConstSampler(true); //new GuaranteedThroughputSampler(samplingRate, lowerBound);
      
      ITracer tracer = new Tracer.Builder(serviceName).WithLoggerFactory(loggerFactory).WithReporter(reporter).WithSampler(sampler).Build();
  
      // Allows code that can't use DI to also access the tracer.
      GlobalTracer.Register(tracer);
  
      return tracer;
  });
  
  services.Configure&lt;HttpHandlerDiagnosticOptions&gt;(options =&gt;
  {
      //options.IgnorePatterns.Add(x =&gt; false);
      options.IgnorePatterns.Add(x =&gt; x.RequestUri.IsLoopback);
      
      options.OnRequest = (span, request) =&gt; 
      {
          span.SetTag(&quot;MyCustomTag&quot;, request.RequestUri.AbsoluteUri);
      };
  
      options.OperationNameResolver = (request) =&gt; 
      {
          return &quot;X-&quot; + request.RequestUri.AbsoluteUri;
      };
  });
  </code></pre>
  <p>To use all this, you need to add a few packages to your project:</p>
  <ol>
  <li><code>dotnet add package OpenTracing.Contrib.NetCore --version 0.6.2</code></li>
  <li><code>dotnet add package Jaeger --version 0.4.1</code></li>
  </ol>
  <p>So this works OK and I get Traces with their Spans showing up in my Jaeger Search UI (http://localhost:16686/search) but it just shows the Trace with my service name (in this case &quot;MySuperCoolWebAPI&quot;) followed by &quot;HTTP GET&quot;:</p>
  <p><a href="https://i.stack.imgur.com/Kk7FO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kk7FO.png" alt="jaeger ui screenshot" /></a></p>
  <p>This is not terribly useful to see &quot;HTTP GET&quot; there. Instead, I want to see the Web API action name or something else that lets me know what kind of request this really is.</p>
  <p>As you can see from my sample code above, I have tried setting the <code>HttpHandlerDiagnosticOptions.OperationNameResolver</code> but this only affects <code>HttpClient</code> calls I make from within my web service. It does not seem to affect how the Trace/Span associated with the request I received is named.</p>
  <p>I also tried setting the Span OperationName in my Web API Controller method using the GlobalTracer like this but this affects an inner span and NOT the main Trace/Span that shows up on the main Jaeger UI search results page:</p>
  <pre><code>OpenTracing.Util.GlobalTracer.Instance.ActiveSpan.SetOperationName(&quot;My Web API Action Name&quot;);
  </code></pre>
  <p>Here you can see the first child Span has its name set to what I forced it to but the main level Span (the parent of the one I changed) is not affected:</p>
  <p><a href="https://i.stack.imgur.com/yfwvD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yfwvD.png" alt="jaeger ui screenshot with child span" /></a></p>
  <p>Is there a way I can set the operation name of the main Span with the Jaeger C# Client?</p>
  <p>Also, I am using .NET Core 3.1 in case that is relevant.</p>