Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenTelemetry library and expose metrics for Witsml requests #2291

Merged
merged 6 commits into from
Apr 9, 2024

Conversation

lindsve
Copy link
Collaborator

@lindsve lindsve commented Mar 11, 2024

Fixes

#2290

Implements OpenTelemetry metrics:

  • witsml_requests_duration_seconds (histogram)
  • witsml_requests_active (counter)

Description

The histogram has been set up with the following buckets: 0.5, 1, 3, 5, 10, 15, 30 and 60 seconds.

When used in an application using the library, the metrics can be added within the AddOpenTelemetry method added by the OpenTelementry SDK:

services.AddOpenTelemetry()
            .WithMetrics(builder =>
            {
                builder.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyApplication"));
                builder.AddWitsmlInstrumentation();

                builder.AddPrometheusExporter();
            });

Example from prometheus export:

# TYPE witsml_requests_duration_seconds histogram
# UNIT witsml_requests_duration_seconds seconds
# HELP witsml_requests_duration_seconds Time spent during requests to a Witsml server
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="0.5"} 31251 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="1"} 31691 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="3"} 31911 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="5"} 31941 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="10"} 31943 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="15"} 31944 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="30"} 31944 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="60"} 31944 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1",le="+Inf"} 31945 1710160333618
witsml_requests_duration_seconds_sum{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1"} 1171 1710160333618
witsml_requests_duration_seconds_count{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="1"} 31945 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="0.5"} 27621 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="1"} 27876 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="3"} 27979 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="5"} 27993 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="10"} 27993 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="15"} 27993 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="30"} 27994 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="60"} 27994 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1",le="+Inf"} 27994 1710160333618
witsml_requests_duration_seconds_sum{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1"} 563 1710160333618
witsml_requests_duration_seconds_count{host="witsml.somewhere.com",method="GetFromStore",objectType="risk",resultCode="1"} 27994 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="0.5"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="1"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="3"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="5"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="10"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="15"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="30"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="60"} 2 1710160333618
witsml_requests_duration_seconds_bucket{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2",le="+Inf"} 2 1710160333618
witsml_requests_duration_seconds_sum{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2"} 0 1710160333618
witsml_requests_duration_seconds_count{host="witsml.somewhere.com",method="GetFromStore",objectType="log",resultCode="2"} 2 1710160333618

# TYPE witsml_requests_active gauge
# HELP witsml_requests_active Number of active requests
witsml_requests_active{host="witsml.somewhere.com",method="GetFromStore",objectType="log"} 1 1710160333618
witsml_requests_active{host="witsml.somewhere.com",method="GetFromStore",objectType="risk"} 2 1710160333618

All metrics are tagged with host, method and objectType. If available, resultCode is also added as a tag.

Note: This has only been tested in a .NET 8 application.

Type of change

  • Bugfix
  • New feature (non-breaking change which adds functionality)
  • Enhancement of existing functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Impacted Areas in Application

  • Frontend
  • API
  • WITSML
  • Other (please describe)

Checklist:

Communication

  • I have made corresponding changes to the documentation
  • PR affects application security

Code quality

  • I have self-reviewed my code
  • No new warnings are generated

Test coverage

  • New code is covered by passing tests

@eliasbruvik
Copy link
Contributor

If this is only supported with .NET 8, we will also need to update the version in the dockerfile for our internal server setup. We should also give a heads up and enough time for anyone else using Witsml Explorer that we will no longer support version 7. At least unless it's possible to only enable this when using .NET 8.

@lindsve
Copy link
Collaborator Author

lindsve commented Mar 11, 2024

If this is only supported with .NET 8, we will also need to update the version in the dockerfile for our internal server setup. We should also give a heads up and enough time for anyone else using Witsml Explorer that we will no longer support version 7. At least unless it's possible to only enable this when using .NET 8.

Good call. I'm not sure if I'm able to fully test this in a .NET 7 environment since I have .NET 8 sdk installed (the Witsml library seems to support multiple versions, currently .NET 6 and 7 although I added .NET 8 in this PR). I'll see if I can create a dummy .NET 7 project and reference a locally built witsml package and see how it goes.

That being said, .NET 8 is the latest LTS release and should be favored over .NET 7. I've also added a PR for updating to .NET 8 here: #2293

@lindsve
Copy link
Collaborator Author

lindsve commented Apr 4, 2024

This PR also fixes an issue with duplicate references in Witsml.csproj that was not discovered in the previous PR (#2293). Discovered in the action that builds and publishes the package after merge.

Src/Witsml/Metrics/WitsmlMethod.cs Show resolved Hide resolved
Src/Witsml/Metrics/WitsmlMetrics.cs Outdated Show resolved Hide resolved
Src/Witsml/WitsmlClient.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@eliasbruvik eliasbruvik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Read issue and PR
  • Pulled branch and manually tested
  • Verify that PR resolves issue
  • Reviewed the code

@lindsve lindsve merged commit 50c22e6 into equinor:main Apr 9, 2024
3 checks passed
@lindsve lindsve deleted the add_opentelemetry_metrics branch April 9, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants