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
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* Attribute `db.system` reports `oracle` when
`Devart.Data.Oracle.Entity.EFCore` is used a provider.
([#2465](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2465))

* 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.
([#2466](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2466))
vladajankovic marked this conversation as resolved.
Show resolved Hide resolved

## 1.10.0-beta.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,20 @@ public override void OnEventWritten(string name, object? payload)
return;
}

if (this.commandTypeFetcher.Fetch(command) is CommandType commandType)
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. 😞

{
var commandText = this.commandTextFetcher.Fetch(command);
switch (commandType)
Expand Down
Loading