Setting up .NET tracing on z/OS

You can set up .NET tracing on z/OS systems by using manual instrumentation. Due to platform limitations, automatic instrumentation is not available on z/OS.

For details about the working of .NET monitoring, see How .NET monitoring works.

Before you begin

To set up .NET Core tracing on z/OS, complete the following steps:

Enabling .NET tracing

On z/OS systems, the CoreCLR Profiling API is not supported. As a result, automatic instrumentation through IL rewriting and native profiler attachment is not available on this platform.

Due to these architectural limitations, you must use manual instrumentation to enable tracing for .NET applications on z/OS.

Instana supports two approaches for manual instrumentation on z/OS:

Method 1: Using Instana SDK

Use the Instana Tracing SDK to create custom spans and traces.

To enable tracing by using the Instana SDK, complete the following steps:

  1. Add the Instana.Tracing.Core.Sdk NuGet package to your project.
  2. Create custom spans in your application code:

    using Instana.Tracing.Sdk.Spans;
    
    // Create an entry span for incoming requests
    using (var span = CustomSpan.Create(SpanType.ENTRY, "operation-name"))
    {
        span.SetServiceName("your-service-name");
        span.SetEndpointName("endpoint-name");
        span.SetData("custom.key", "custom-value");
    
        // Your application logic here
    }
    
    // Create an intermediate span for internal operations
    using (var span = CustomSpan.Create(SpanType.INTERMEDIATE, "internal-operation"))
    {
        span.SetServiceName("your-service-name");
        span.SetEndpointName("operation-name");
    
        // Your internal logic here
    }
  3. Optional: Configure the Instana tracer in your application startup code (typically in Program.cs) to set default service and endpoint names that are displayed in traces:

    using Instana.Tracing.Sdk;
    
    // Configure Instana Tracer
    TracerConfiguration.ServiceName = "your-service-name";
    TracerConfiguration.EndpointName = "your-endpoint-name";
  4. Deploy and start the application. Generate traffic to the application endpoints.
  5. Verify that traces are being collected:

    1. Go to Applications > Services in the Instana UI.
    2. Locate the service name to view its traces and metrics.

For more information about Instana .NET Core Tracing SDK, see .NET or .NET Core Tracing SDK.

Method 2: Using OpenTelemetry SDK

Use the OpenTelemetry SDK with OTLP exporter to send traces to Instana.

Before you use the OpenTelemetry SDK, configure the Instana agent to accept OpenTelemetry data by enabling the following configuration in the agent configuration file <agent-root-path>/agent/etc/instana/configuration.yaml:

# Enable OpenTelemetry
com.instana.plugin.opentelemetry:
  grpc:
    enabled: true
  http:
    enabled: true

# Enable .NET Core AutoTracing
com.instana.plugin.netcore:
  tracing:
    enabled: true

To enable tracing by using the OpenTelemetry SDK, complete the following steps:

  1. Add the required OpenTelemetry NuGet packages to your project:

    • OpenTelemetry.Extensions.Hosting
    • OpenTelemetry.Exporter.OpenTelemetryProtocol
    • OpenTelemetry.Exporter.Console (if console-based logging is required)
    • OpenTelemetry.Instrumentation.AspNetCore (for ASP.NET Core web applications)
    • OpenTelemetry.Instrumentation.Http (for HTTP client instrumentation)
  2. Configure OpenTelemetry in your application startup code (typically in Program.cs):

    using OpenTelemetry.Resources;
    using OpenTelemetry.Trace;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Configure OpenTelemetry
    builder.Services.AddOpenTelemetry()
        .ConfigureResource(resource =>
        {
            resource.AddService(
                serviceName: "your-service-name",
                serviceVersion: "1.0.0",
                serviceInstanceId: Environment.ProcessId.ToString());
        })
        .WithTracing(tracing =>
        {
            tracing
                .AddSource("your-service-name")
                .AddAspNetCoreInstrumentation()
                .AddHttpClientInstrumentation()
                .AddOtlpExporter(options =>
                {
                    // Configure OTLP endpoint to point to Instana Agent
                    options.Endpoint = new Uri("http://localhost:4317");
                });
        });
  3. Create custom spans by using OpenTelemetry ActivitySource:

    using System.Diagnostics;
    
    // Create an ActivitySource
    private static readonly ActivitySource ActivitySource = new ActivitySource("your-service-name", "1.0.0");
    
    // Create custom spans
    using (var activity = ActivitySource.StartActivity("operation-name"))
    {
        activity?.SetTag("custom.key", "custom-value");
        activity?.SetTag("operation.type", "business-logic");
    
        // Your application logic here
    
        activity?.AddEvent(new ActivityEvent("Operation completed"));
    }
  4. Deploy and start the application. Generate traffic to the application endpoints.
  5. Verify that traces are being collected:

    1. Go to Applications > Services in the Instana UI.
    2. Locate the service name to view its traces and metrics.