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

chore(graphql): Removed Application Insights SDK, added OpenTelemetry #1349

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

knuhau
Copy link
Collaborator

@knuhau knuhau commented Oct 25, 2024

Description

Removed Application Insights SDK, added OpenTelemetry

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced OpenTelemetryEventListener for enhanced tracing and monitoring of GraphQL requests.
    • Updated telemetry configuration to streamline logging and ensure consistent telemetry setup.
  • Bug Fixes

    • Removed the deprecated ApplicationInsightEventListener, improving the overall telemetry approach.
  • Refactor

    • Adjusted service collection to replace the event listener for GraphQL with the new OpenTelemetry implementation.

@knuhau knuhau requested a review from a team as a code owner October 25, 2024 07:45
Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces significant changes to the telemetry tracking within the GraphQL application. The ApplicationInsightEventListener class has been removed and replaced with the OpenTelemetryEventListener class, which uses OpenTelemetry for tracing GraphQL requests. Additionally, the Program.cs file has been updated to streamline telemetry configuration, while the ServiceCollectionExtensions class reflects this change by updating the event listener registration. Overall, these modifications enhance the observability of the application by integrating OpenTelemetry.

Changes

File Path Change Summary
src/Digdir.Domain.Dialogporten.GraphQL/ApplicationInsightEventListener.cs - Class removed: ApplicationInsightEventListener
- Class removed: ScopeWithEndAction
src/Digdir.Domain.Dialogporten.GraphQL/OpenTelemetryEventListener.cs - Class added: OpenTelemetryEventListener
- Methods added: ExecuteRequest, RequestError, ValidationErrors
- Class added: ScopeWithEndAction
- Constructor added: ScopeWithEndAction(Action disposeAction)
src/Digdir.Domain.Dialogporten.GraphQL/Program.cs - Method signature updated: BuildAndRun to accept TelemetryConfiguration
src/Digdir.Domain.Dialogporten.GraphQL/ServiceCollectionExtensions.cs - Method signature updated: Changed from ApplicationInsightEventListener to OpenTelemetryEventListener in AddDiagnosticEventListener

Possibly related PRs

Suggested reviewers

  • oskogstad
  • arealmaas

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
src/Digdir.Domain.Dialogporten.GraphQL/Program.cs (1)

Line range hint 20-86: Documentation and testing needed for telemetry changes.

As mentioned in the PR objectives, documentation and tests are missing. Consider:

  1. Adding XML documentation comments explaining the telemetry setup
  2. Creating integration tests to verify:
    • Proper span creation and propagation
    • Correct attribute injection
    • Sampling behavior

Would you like help with:

  1. Generating documentation templates for the telemetry configuration?
  2. Creating test examples for OpenTelemetry integration?
src/Digdir.Domain.Dialogporten.GraphQL/OpenTelemetryEventListener.cs (1)

35-35: Use standard attribute key enduser.id for authenticated user

According to OpenTelemetry Semantic Conventions, the attribute key for capturing the authenticated user ID is enduser.id. Using the standard key ensures consistency and better interoperability with OpenTelemetry-compatible tools.

Apply this diff to update the attribute key:

-            activity.SetTag("user.id", httpContext.User.Identity?.Name ?? "Not authenticated");
+            activity.SetTag("enduser.id", httpContext.User.Identity?.Name ?? "Not authenticated");
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0c0a4da and aab39ec.

📒 Files selected for processing (4)
  • src/Digdir.Domain.Dialogporten.GraphQL/ApplicationInsightEventListener.cs (0 hunks)
  • src/Digdir.Domain.Dialogporten.GraphQL/OpenTelemetryEventListener.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.GraphQL/Program.cs (5 hunks)
  • src/Digdir.Domain.Dialogporten.GraphQL/ServiceCollectionExtensions.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/Digdir.Domain.Dialogporten.GraphQL/ApplicationInsightEventListener.cs
🔇 Additional comments (4)
src/Digdir.Domain.Dialogporten.GraphQL/ServiceCollectionExtensions.cs (1)

19-19: LGTM! Change aligns with the transition to OpenTelemetry.

The replacement of the diagnostic event listener is consistent with the PR objective of migrating from Application Insights to OpenTelemetry.

src/Digdir.Domain.Dialogporten.GraphQL/Program.cs (3)

33-33: LGTM! Good practice passing telemetry configuration.

The updated method signature properly injects the telemetry configuration, ensuring consistent configuration throughout the application.


86-86: LGTM! Proper service registration.

The HttpContextAccessor registration is correctly placed and follows dependency injection best practices.


20-28: Verify the continued use of Application Insights in logging configuration.

While transitioning to OpenTelemetry, the code still uses Application Insights for logging. Is this intentional for a gradual transition? If not, consider updating the logging configuration to use OpenTelemetry's logging provider instead.

✅ Verification successful

Application Insights usage is part of an ongoing transition to OpenTelemetry

The continued use of Application Insights in the logging configuration is intentional and correct at this stage because:

  1. The codebase shows a clear transition pattern where both systems coexist:
    • OpenTelemetry is being integrated for tracing with the new OpenTelemetryEventListener
    • Application Insights is still handling logging through Serilog across multiple services
  2. The transition is being handled systematically through AspNetUtilitiesExtensions.cs which:
    • Configures OpenTelemetry as the primary telemetry system
    • Falls back to Application Insights SDK for local development
    • Uses Azure Monitor OpenTelemetry exporter when Application Insights connection string is present

This mixed usage is a recommended approach for gradually transitioning between telemetry systems while maintaining observability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Application Insights is still used elsewhere in the codebase
rg -l "ApplicationInsights" --type cs

Length of output: 446


Script:

#!/bin/bash
# Let's check the actual usage context of ApplicationInsights in these files
for file in $(rg -l "ApplicationInsights" --type cs); do
    echo "=== $file ==="
    rg "ApplicationInsights" -B 2 -A 2 "$file"
done

Length of output: 6120


Script:

#!/bin/bash
# Check for OpenTelemetry usage to understand the transition state
rg "OpenTelemetry" -B 2 -A 2 --type cs

Length of output: 3986


Script:

#!/bin/bash
# Check if there are any OpenTelemetry logging providers configured
ast-grep --pattern 'AddOpenTelemetry()$$$'

Length of output: 44

Copy link

sonarqubecloud bot commented Nov 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
3.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@oskogstad oskogstad merged commit 16f3b38 into main Nov 5, 2024
22 of 23 checks passed
@oskogstad oskogstad deleted the chore/graphql-opentelemetry branch November 5, 2024 14:04
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.

3 participants