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

[Instrumentation.EntityFrameworkCore] Fix db.statement tag for Devart Oracle #2466

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

vladajankovic
Copy link
Contributor

Fixes #2462

Changes

Added code to fix exception thrown when Devart Oracle is used (this.commandTypeFetcher.Fetch(command)).
If Devart Oracle is used, the SQL statement will be extracted from the payload.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@vladajankovic vladajankovic requested a review from a team as a code owner January 15, 2025 16:44
@github-actions github-actions bot added the comp:instrumentation.entityframeworkcore Things related to OpenTelemetry.Instrumentation.EntityFrameworkCore label Jan 15, 2025
Comment on lines 203 to 216
if (command.GetType().FullName?.Contains("Devart.Data.Oracle") == true)
{
string payloadString = payload?.ToString() ?? string.Empty;
if ((payloadString.Contains("CommandType='Text'") && this.options.SetDbStatementForText) ||
(payloadString.Contains("CommandType='StoredProcedure'") && this.options.SetDbStatementForStoredProcedure))
{
string[] result = payloadString.Split(['\n'], 2);
if (result.Length > 1)
{
activity.AddTag(AttributeDbStatement, result[1]);
}
}
}
else if (this.commandTypeFetcher.Fetch(command) is CommandType commandType)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is couple things you should consider here:

  1. Support both for emitting old and new attributes. See lese if statement for details:
                                    if (this.options.SetDbStatementForStoredProcedure)
                                    {
                                        if (this.options.EmitOldAttributes)
                                        {
                                            activity.AddTag(AttributeDbStatement, commandText);
                                        }
                                        if (this.options.EmitNewAttributes)
                                        {
                                            activity.AddTag(AttributeDbQueryText, commandText);
                                        }
                                    }
  1. payloadString split, is it always '\n' or it can be vary based on the environment settings?
  2. Consider adding stub/mocked tests for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I was writing this code based on an older version (1.0.0-beta.10) that didn't have this.options.EmitOldAttributes and this.options.EmitNewAttributes. So, I will update the code structure to follow the convention of the switch statement.

  2. Updated the line as follows: string[] result = payloadString.Split([Environment.NewLine], 2, StringSplitOptions.None);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I am unable to write mock tests because Devart requires a license in order to connect to Oracle database. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.entityframeworkcore Things related to OpenTelemetry.Instrumentation.EntityFrameworkCore
Projects
None yet
2 participants