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 config for enriching activity with read-result-set-header #1538

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/MySqlConnector/Core/ConnectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
UseAffectedRows = csb.UseAffectedRows;
UseCompression = csb.UseCompression;
UseXaTransactions = csb.UseXaTransactions;
EnrichActivityWithReadResultSetHeader = csb.EnrichActivityWithReadResultSetHeader;

static int ToSigned(uint value) => value >= int.MaxValue ? int.MaxValue : (int) value;
}
Expand Down Expand Up @@ -245,6 +246,7 @@ private static MySqlGuidFormat GetEffectiveGuidFormat(MySqlGuidFormat guidFormat
public bool UseAffectedRows { get; }
public bool UseCompression { get; }
public bool UseXaTransactions { get; }
public bool EnrichActivityWithReadResultSetHeader { get; }

public byte[]? ConnectionAttributes { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/MySqlConnector/Core/ResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior)
ContainsCommandParameters = true;
WarningCount = 0;
State = ResultSetState.ReadResultSetHeader;
if (DataReader.Activity is { IsAllDataRequested: true })
if (DataReader.Activity is { IsAllDataRequested: true } && Connection.EnrichActivityWithReadResultSetHeader)
DataReader.Activity.AddEvent(new ActivityEvent("read-result-set-header"));
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/MySqlConnector/MySqlConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
internal bool NoBackslashEscapes => GetInitializedConnectionSettings().NoBackslashEscapes;
internal bool TreatTinyAsBoolean => GetInitializedConnectionSettings().TreatTinyAsBoolean;
internal IOBehavior AsyncIOBehavior => GetConnectionSettings().ForceSynchronous ? IOBehavior.Synchronous : IOBehavior.Asynchronous;
internal bool EnrichActivityWithReadResultSetHeader => GetInitializedConnectionSettings().EnrichActivityWithReadResultSetHeader;

// Defaults to IOBehavior.Synchronous if the connection hasn't been opened yet; only use if it's a no-op for a closed connection.
internal IOBehavior SimpleAsyncIOBehavior => (m_connectionSettings?.ForceSynchronous is true) ? IOBehavior.Synchronous : IOBehavior.Asynchronous;
Expand Down
18 changes: 18 additions & 0 deletions src/MySqlConnector/MySqlConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,19 @@ public bool UseXaTransactions
set => MySqlConnectionStringOption.UseXaTransactions.SetValue(this, value);
}

/// <summary>
/// Enrich Activity with read-result-set-header
/// </summary>
[Category("Other")]
[DefaultValue(true)]
[Description("Enriches Activity with read-result-set-header events.")]
[DisplayName("Enrich Activity with read-result-set-header")]
public bool EnrichActivityWithReadResultSetHeader
{
get => MySqlConnectionStringOption.EnrichActivityWithReadResultSetHeader.GetValue(this);
set => MySqlConnectionStringOption.EnrichActivityWithReadResultSetHeader.SetValue(this, value);
}

// Other Methods

/// <summary>
Expand Down Expand Up @@ -958,6 +971,7 @@ internal abstract partial class MySqlConnectionStringOption
public static readonly MySqlConnectionStringValueOption<bool> UseAffectedRows;
public static readonly MySqlConnectionStringValueOption<bool> UseCompression;
public static readonly MySqlConnectionStringValueOption<bool> UseXaTransactions;
public static readonly MySqlConnectionStringValueOption<bool> EnrichActivityWithReadResultSetHeader;

public static MySqlConnectionStringOption? TryGetOptionForKey(string key) =>
s_options.TryGetValue(key, out var option) ? option : null;
Expand Down Expand Up @@ -1262,6 +1276,10 @@ static MySqlConnectionStringOption()
AddOption(options, UseXaTransactions = new(
keys: ["Use XA Transactions", "UseXaTransactions"],
defaultValue: true));

AddOption(options, EnrichActivityWithReadResultSetHeader = new(
keys: ["Enrich Activity with ReadResultSetHeader", "EnrichActivityWithReadResultSetHeader"],
defaultValue: true));
#pragma warning restore SA1118 // Parameter should not span multiple lines

#if NET8_0_OR_GREATER
Expand Down
Loading