• English日本語한국어
  • 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.

Note: null values will not be recorded.

.NET type

How the value will be represented

byte, Int16, Int32, Int64

sbyte, UInt16, UInt32, UInt64

As an integral value.

float, double, decimal

A decimal-based number.

string

A string truncated after 255-bytes.

Empty strings are supported.

bool

True or false.

DateTime

A string representation following the ISO-8601 format, including time zone information:

Example: 2020-02-13T11:31:19.5767650-08:00

TimeSpan

A decimal-based number representing number of seconds.

everything else

The ToString() method will be applied. Custom types must have an implementation of Object.ToString() or they will throw an exception.

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 © 2024 New Relic Inc.

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