Hands-On OpenTelemetry, Docker, and K8s

Deploy a .NET Application

10 minutes

Prerequisites

Before deploying the application, we’ll need to install the .NET 8 SDK on our instance.

bash
sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-8.0

Refer to Install .NET SDK or .NET Runtime on Ubuntu for further details.

Review the .NET Application

In the terminal, navigate to the application directory:

bash
cd ~/workshop/docker-k8s-otel/helloworld

We’ll use a simple “Hello World” .NET application for this workshop. The main logic is found in the HelloWorldController.cs file:

cs
public class HelloWorldController : ControllerBase
{
    private ILogger<HelloWorldController> logger;

    public HelloWorldController(ILogger<HelloWorldController> logger)
    {
        this.logger = logger;
    }

    [HttpGet("/hello/{name?}")]
    public string Hello(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
           logger.LogInformation("/hello endpoint invoked anonymously");
           return "Hello, World!";
        }
        else
        {
            logger.LogInformation("/hello endpoint invoked by {name}", name);
            return String.Format("Hello, {0}!", name);
        }
    }
}

Build and Run the .NET Application

We can build the application using the following command:

bash
dotnet build

If that’s successful, we can run it as follows:

bash
dotnet run

Once it’s running, open a second SSH terminal to your Ubuntu instance and access the application using curl:

bash
curl http://localhost:8080/hello

You can also pass in your name:

bash
curl http://localhost:8080/hello/Tom

Press Ctrl + C to quit your Helloworld app before moving to the next step.

Next Steps

What are the three methods that we can use to instrument our application with OpenTelemetry?

Traces

See: Instrument your .NET application for Splunk Observability Cloud for a discussion of the options.

Last Modified ·