Coder Social home page Coder Social logo

honeycombio / intro-to-o11y-dotnet Goto Github PK

View Code? Open in Web Editor NEW
1.0 33.0 9.0 115 KB

An instrumented microservice in .NET - it'll give you some Honeycomb data to play with.

License: Apache License 2.0

Dockerfile 7.03% Shell 17.54% C# 31.67% HTML 21.83% CSS 8.02% JavaScript 13.92%

intro-to-o11y-dotnet's Introduction

Intro to Observability: OpenTelemetry in .NET

This ASP.NET application is here for you to try out tracing with Honeycomb. It consists of a microservice that calls itself, so you can simulate a whole microservice ecosystem with just one service!

What to do

Recommended:

Open in Gitpod

Gitpod is a free cloud environment where you can run the example without needing to clone the code to your machine.

You can also clone this repo and run the app locally in VSCode or Visual Studio.

Starting the app

dotnet run

Accessing the app

If you are running the app in Gitpod, navigate to the "Ports" tab and click the address for port 5000 to open the app in a new tab:

Gitpod open address

If you are running locally, access the app at http://localhost:5000.

Activate the sequence of numbers by selecting the Go button. After the app displays numbers, select Stop. Try this a few times.

Once that works, stop the app and configure it to send traces.

Stopping the app

Push Ctrl-C in the terminal where it's running.

Connect to Honeycomb

Our goal is to configure the connection to send traces to Honeycomb.

Open appsettings.json

Find the "Honeycomb" section.

Update the "ApiKey" property. Try not to commit this file with your key in it.

Get a Honeycomb API Key from your Team Settings in Honeycomb. (find this by clicking on your profile in the lower-left corner.)

Alternative: you can set these on the command line.

export HONEYCOMB__APIKEY=<your api key here>
export HONEYCOMB__SERVICENAME=fib-microsvc

dotnet run

You can use whatever service name you like.

If you are running the app in Gitpod, navigate to the "Ports" tab and click the address for port 5000 to open the app in a new tab:

Gitpod open address

If you are running locally, access the app at http://localhost:5000.

See the results

Run the app. Push "Go" to activate the sequence of numbers, the "Stop". Do that several times.

Go to Honeycomb and choose the Dataset that matches the service name you configured (default is fib-microsvc).

In Part 2 of the workshop, explore the data you find there.

Customize a span: custom attributes

This is for Part 3 of the workshop.

Let's make it easier to see what the "index" query parameter is.

In Controllers/FibonacciController.cs, find the "CUSTOM ATTRIBUTE" comment. Uncomment these lines:

var currentSpan = Tracer.CurrentSpan;
currentSpan.SetAttribute("parameter.index", index);

This will add that parameter information to the current span.

Wait for the app to restart... and then try out the app again (push Go, then Stop). Can you find the field in honeycomb?

FYI, tracing is also a .NET Activity

You don't even have to access OpenTelemetry directly to do this. You can use the built-in .NET concept of Activity.

In FibonacciController.cs, add the index parameter as a custom attribute like this:

System.Diagnostics.Activity.Current.AddTag("parameter.index", iv.ToString());

Restart the app, make the sequence go, and find that field on the new spans.

Can you make the trace waterfall view show the index? What pattern does it show?

3. Create a custom span

Make the calculation into its own span, to see how much of the time spent on this service is the meat: adding the fibonacci numbers.

Find the "CUSTOM SPAN" comment, and uncomment the sections below it.

After a restart, do your traces show this extra span? Do you see the name of your method? What percentage of the service time is spend in it?

How does this work?

Autoinstrumentation!

This tracing happens with only one code change.

See the "Tracing!" comment in Startup.cs. That is where OpenTelemetry instrumentation is set up.

This sets up auto-instrumentation for ASP.NET Core, and configures it to send to Honeycomb based on environment variables.

You'll see the web requests coming in. They'll even nest inside each other when the service calls itself. You will not yet see information that is special to this app, like the query parameter on the request.

Updating libraries

For maintaining this project, this section reminds us how to check that we're on the latest Honeycomb OpenTelemetry Distribution for .NET.

Check the .csproj file against the latest release.

Update the version in the .csproj file if necessary, and then 'dotnet run' will get the new version.

Troubleshooting

Our documentation: https://docs.honeycomb.io/getting-data-in/dotnet/opentelemetry-distro/

If you see this error: Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. ... then you probably need to define the HONEYCOMB__APIKEY environment variable before running the app.

If you see the warnings Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'. or Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. ... then ignore it. We aren't using IPv6 here.

intro-to-o11y-dotnet's People

Contributors

craigatk avatar jessitron avatar martinjt avatar priorax avatar vreynolds avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

intro-to-o11y-dotnet's Issues

Demo does not work with latest Honeycomb.OpenTelemetry release

Versions
HoneyComb.OpenTelemety 1.2.1

Steps to reproduce

Followed instructions in README for

Updating libraries
For maintaining this project, this section reminds us how to check that we're on the latest Honeycomb OpenTelemetry Distribution for .NET.

Bumped to 1.2.1

Ran ./run

Following error was produced:

gitpod /workspace/intro-to-o11y-dotnet (main) $ ./run 
Reading .env
Building...
/workspace/intro-to-o11y-dotnet/Startup.cs(34,22): error CS1061: 'IServiceCollection' does not contain a definition for 'AddHoneycomb' and no accessible extension method 'AddHoneycomb' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) [/workspace/intro-to-o11y-dotnet/intro-to-observability-dotnet.csproj]

The build failed. Fix the build errors and run again.

Additional context

Currently not running on gitpod

Versions
.NET 6.0

Steps to reproduce

  1. Open new gitpod instance
  2. Run ./run

Error produced:

Reading .env
Building...
You must install or update .NET to run this application.

App: /workspace/intro-to-o11y-dotnet/bin/Debug/net6.0/intro-to-observability-dotnet
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64)
.NET location: /home/gitpod/dotnet

The following frameworks were found:
  7.0.0 at [/home/gitpod/dotnet/shared/Microsoft.NETCore.App]

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=ubuntu.20.04-x64

Additional context
.NET 7 was recently released and it looks like this may be a contributing factor as gitpod has bumped the release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.