• Log inStart now

ISpan

Syntax

Public interface ISpan

Provides access to span-specific methods in the New Relic API.

Description

Provides access to span-specific methods in the New Relic .NET agent API. To obtain a reference to ISpan, use:

  • The CurrentSpan property on IAgent (Recommended).
  • The CurrentSpan property on ITransaction.

This section contains descriptions and parameters of ISpan methods:

Name

Description

AddCustomAttribute

Add contextual information from your application to the current span in form of attributes.

SetName

Changes the name of the current span/segment/metrics that will be reported to New Relic.

AddCustomAttribute

Adds contextual information about your application to the current span in the form of attributes.

This method requires .NET agent version and .NET agent API version 8.25 or higher.

Syntax

ISpan AddCustomAttribute(string key, object value)

Parameters

Parameter

Description

key

string

Identifies the information being reported. Also known as the name.

  • Empty keys are not supported.
  • Keys are limited to 255-bytes. Attributes with keys larger than 255-bytes will be ignored.

value

object

The value being reported.

Returns

A reference to the current span.

Usage considerations

For details about supported data types, see the Custom Attributes guide.

Examples

IAgent agent = NewRelic.Api.Agent.NewRelic.GetAgent();
ISpan currentSpan = agent.CurrentSpan;
currentSpan
.AddCustomAttribute("customerName","Bob Smith")
.AddCustomAttribute("currentAge",31)
.AddCustomAttribute("birthday", new DateTime(2000, 02, 14))
.AddCustomAttribute("waitTime", TimeSpan.FromMilliseconds(93842));

SetName

Changes the name of the current segment/span that will be reported to New Relic. For segments/spans resulting from custom instrumentation, the metric name reported to New Relic will be altered as well.

This method requires .NET agent version and .NET agent API version 10.1.0 or higher.

Syntax

ISpan SetName(string name)

Parameters

Parameter

Description

name

string

The new name for the span/segment.

Returns

A reference to the current span.

Examples

[Trace]
public void MyTracedMethod()
{
IAgent agent = NewRelic.Api.Agent.NewRelic.GetAgent();
ISpan currentSpan = agent.CurrentSpan;
currentSpan.SetName("MyCustomName");
Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.