Skip to content

Commit

Permalink
Fix dotnet#3422 - React to Telemetry renames
Browse files Browse the repository at this point in the history
  • Loading branch information
mikary committed Oct 19, 2015
1 parent 36c7ef5 commit 4de4695
Showing 25 changed files with 153 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@
<Link>Extensions\AsyncEnumerableExtensions.cs</Link>
</Compile>
<Compile Include="Extensions\DbCommandLogData.cs" />
<Compile Include="Internal\RelationalTelemetry.cs" />
<Compile Include="Internal\RelationalDiagnostics.cs" />
<Compile Include="..\Shared\LoggingExtensions.cs">
<Link>Extensions\LoggingExtensions.cs</Link>
</Compile>
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Migrations;
@@ -35,10 +35,8 @@ public static EntityFrameworkServicesBuilder AddRelational([NotNull] this Entity

builder.GetService()
.TryAdd(new ServiceCollection()
#pragma warning disable 0618
.AddSingleton(s => new TelemetryListener("Microsoft.Data.Entity"))
.AddSingleton<TelemetrySource>(s => s.GetService<TelemetryListener>())
#pragma warning restore 0618
.AddSingleton(s => new DiagnosticListener("Microsoft.Data.Entity"))
.AddSingleton<DiagnosticSource>(s => s.GetService<DiagnosticListener>())
.AddSingleton<ParameterNameGeneratorFactory>()
.AddSingleton<IComparer<ModificationCommand>, ModificationCommandComparer>()
.AddSingleton<IMigrationsIdGenerator, MigrationsIdGenerator>()
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@

using System;
using System.Data.Common;
using System.Diagnostics.Tracing;
using System.Diagnostics;

namespace Microsoft.Data.Entity.Internal
{
internal static class RelationalTelemetry
internal static class RelationalDiagnostics
{
private const string NamePrefix = "Microsoft.Data.Entity.";

@@ -22,18 +22,17 @@ public static class ExecuteMethod
public const string ExecuteNonQuery = nameof(ExecuteNonQuery);
}

#pragma warning disable 0618
public static void WriteCommand(
this TelemetrySource telemetrySource,
string telemetryName,
this DiagnosticSource diagnosticSource,
string diagnosticName,
DbCommand command,
string executeMethod,
bool async)
{
if (telemetrySource.IsEnabled(telemetryName))
if (diagnosticSource.IsEnabled(diagnosticName))
{
telemetrySource.WriteTelemetry(
telemetryName,
diagnosticSource.Write(
diagnosticName,
new
{
Command = command,
@@ -44,15 +43,15 @@ public static void WriteCommand(
}

public static void WriteCommandError(
this TelemetrySource telemetrySource,
this DiagnosticSource diagnosticSource,
DbCommand command,
string executeMethod,
bool async,
Exception exception)
{
if (telemetrySource.IsEnabled(CommandExecutionError))
if (diagnosticSource.IsEnabled(CommandExecutionError))
{
telemetrySource.WriteTelemetry(
diagnosticSource.Write(
CommandExecutionError,
new
{
@@ -63,6 +62,5 @@ public static void WriteCommandError(
});
}
}
#pragma warning restore 0618
}
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Reflection;
using System.Threading;
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@@ -16,28 +16,26 @@ namespace Microsoft.Data.Entity.Storage.Internal
{
public class RelationalCommand : IRelationalCommand
{
#pragma warning disable 0618
public RelationalCommand(
[NotNull] ISensitiveDataLogger logger,
[NotNull] TelemetrySource telemetrySource,
[NotNull] DiagnosticSource diagnosticSource,
[NotNull] string commandText,
[NotNull] IReadOnlyList<RelationalParameter> parameters)
{
Check.NotNull(logger, nameof(logger));
Check.NotNull(telemetrySource, nameof(telemetrySource));
Check.NotNull(diagnosticSource, nameof(diagnosticSource));
Check.NotNull(commandText, nameof(commandText));
Check.NotNull(parameters, nameof(parameters));

Logger = logger;
TelemetrySource = telemetrySource;
DiagnosticSource = diagnosticSource;
CommandText = commandText;
Parameters = parameters;
}

protected virtual ISensitiveDataLogger Logger { get; }

protected virtual TelemetrySource TelemetrySource { get; }
#pragma warning restore 0618
protected virtual DiagnosticSource DiagnosticSource { get; }

public virtual string CommandText { get; }

@@ -54,7 +52,7 @@ public virtual void ExecuteNonQuery([NotNull] IRelationalConnection connection)
return c.ExecuteNonQuery();
}
},
RelationalTelemetry.ExecuteMethod.ExecuteNonQuery);
RelationalDiagnostics.ExecuteMethod.ExecuteNonQuery);

public virtual async Task ExecuteNonQueryAsync(
[NotNull] IRelationalConnection connection,
@@ -68,7 +66,7 @@ public virtual async Task ExecuteNonQueryAsync(
return await c.ExecuteNonQueryAsync(ct);
}
},
RelationalTelemetry.ExecuteMethod.ExecuteNonQuery,
RelationalDiagnostics.ExecuteMethod.ExecuteNonQuery,
cancellationToken);

public virtual object ExecuteScalar([NotNull] IRelationalConnection connection)
@@ -81,7 +79,7 @@ public virtual object ExecuteScalar([NotNull] IRelationalConnection connection)
return c.ExecuteScalar();
}
},
RelationalTelemetry.ExecuteMethod.ExecuteScalar);
RelationalDiagnostics.ExecuteMethod.ExecuteScalar);

public virtual async Task<object> ExecuteScalarAsync(
[NotNull] IRelationalConnection connection,
@@ -95,7 +93,7 @@ public virtual async Task<object> ExecuteScalarAsync(
return await c.ExecuteScalarAsync(ct);
}
},
RelationalTelemetry.ExecuteMethod.ExecuteScalar,
RelationalDiagnostics.ExecuteMethod.ExecuteScalar,
cancellationToken);

public virtual RelationalDataReader ExecuteReader([NotNull] IRelationalConnection connection)
@@ -113,7 +111,7 @@ public virtual RelationalDataReader ExecuteReader([NotNull] IRelationalConnectio
throw;
}
},
RelationalTelemetry.ExecuteMethod.ExecuteReader);
RelationalDiagnostics.ExecuteMethod.ExecuteReader);

public virtual async Task<RelationalDataReader> ExecuteReaderAsync(
[NotNull] IRelationalConnection connection,
@@ -132,7 +130,7 @@ public virtual async Task<RelationalDataReader> ExecuteReaderAsync(
throw;
}
},
RelationalTelemetry.ExecuteMethod.ExecuteReader,
RelationalDiagnostics.ExecuteMethod.ExecuteReader,
cancellationToken);

protected virtual T Execute<T>(
@@ -142,8 +140,8 @@ protected virtual T Execute<T>(
{
var dbCommand = CreateCommand(connection);

WriteTelemetry(
RelationalTelemetry.BeforeExecuteCommand,
WriteDiagnostic(
RelationalDiagnostics.BeforeExecuteCommand,
dbCommand,
executeMethod);

@@ -155,7 +153,7 @@ protected virtual T Execute<T>(
}
catch (Exception exception)
{
TelemetrySource
DiagnosticSource
.WriteCommandError(
dbCommand,
executeMethod,
@@ -165,8 +163,8 @@ protected virtual T Execute<T>(
throw;
}

WriteTelemetry(
RelationalTelemetry.AfterExecuteCommand,
WriteDiagnostic(
RelationalDiagnostics.AfterExecuteCommand,
dbCommand,
executeMethod);

@@ -181,8 +179,8 @@ protected virtual async Task<T> ExecuteAsync<T>(
{
var dbCommand = CreateCommand(connection);

WriteTelemetry(
RelationalTelemetry.BeforeExecuteCommand,
WriteDiagnostic(
RelationalDiagnostics.BeforeExecuteCommand,
dbCommand,
executeMethod,
async: true);
@@ -195,7 +193,7 @@ protected virtual async Task<T> ExecuteAsync<T>(
}
catch (Exception exception)
{
TelemetrySource
DiagnosticSource
.WriteCommandError(
dbCommand,
executeMethod,
@@ -205,21 +203,21 @@ protected virtual async Task<T> ExecuteAsync<T>(
throw;
}

WriteTelemetry(
RelationalTelemetry.AfterExecuteCommand,
WriteDiagnostic(
RelationalDiagnostics.AfterExecuteCommand,
dbCommand,
executeMethod,
async: true);

return result;
}

private void WriteTelemetry(
private void WriteDiagnostic(
string name,
DbCommand command,
string executeMethod,
bool async = false)
=> TelemetrySource.WriteCommand(
=> DiagnosticSource.WriteCommand(
name,
command,
executeMethod,
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Internal;
@@ -14,25 +14,23 @@ namespace Microsoft.Data.Entity.Storage.Internal
public class RelationalCommandBuilder : IRelationalCommandBuilder
{
private readonly ISensitiveDataLogger _logger;
#pragma warning disable 0618
private readonly TelemetrySource _telemetrySource;
private readonly DiagnosticSource _diagnosticSource;
private readonly IRelationalTypeMapper _typeMapper;
private readonly List<RelationalParameter> _parameters = new List<RelationalParameter>();

public RelationalCommandBuilder(
[NotNull] ISensitiveDataLogger logger,
[NotNull] TelemetrySource telemetrySource,
[NotNull] DiagnosticSource diagnosticSource,
[NotNull] IRelationalTypeMapper typeMapper)
{
Check.NotNull(logger, nameof(logger));
Check.NotNull(telemetrySource, nameof(telemetrySource));
Check.NotNull(diagnosticSource, nameof(diagnosticSource));
Check.NotNull(typeMapper, nameof(typeMapper));

_logger = logger;
_telemetrySource = telemetrySource;
_diagnosticSource = diagnosticSource;
_typeMapper = typeMapper;
}
#pragma warning restore 0618

public virtual IndentedStringBuilder CommandTextBuilder { get; } = new IndentedStringBuilder();

@@ -58,7 +56,7 @@ public virtual IRelationalCommandBuilder AddParameter(
public virtual IRelationalCommand BuildRelationalCommand()
=> new RelationalCommand(
_logger,
_telemetrySource,
_diagnosticSource,
CommandTextBuilder.ToString(),
_parameters);

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Diagnostics.Tracing;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Utilities;
@@ -11,29 +11,27 @@ namespace Microsoft.Data.Entity.Storage.Internal
public class RelationalCommandBuilderFactory : IRelationalCommandBuilderFactory
{
private readonly ISensitiveDataLogger _logger;
#pragma warning disable 0618
private readonly TelemetrySource _telemetrySource;
private readonly DiagnosticSource _diagnosticSource;
private readonly IRelationalTypeMapper _typeMapper;

public RelationalCommandBuilderFactory(
[NotNull] ISensitiveDataLogger<RelationalCommandBuilderFactory> logger,
[NotNull] TelemetrySource telemetrySource,
[NotNull] DiagnosticSource diagnosticSource,
[NotNull] IRelationalTypeMapper typeMapper)
{
Check.NotNull(logger, nameof(logger));
Check.NotNull(telemetrySource, nameof(telemetrySource));
Check.NotNull(diagnosticSource, nameof(diagnosticSource));
Check.NotNull(typeMapper, nameof(typeMapper));

_logger = logger;
_telemetrySource = telemetrySource;
_diagnosticSource = diagnosticSource;
_typeMapper = typeMapper;
}
#pragma warning restore 0618

public virtual IRelationalCommandBuilder Create()
=> new RelationalCommandBuilder(
_logger,
_telemetrySource,
_diagnosticSource,
_typeMapper);
}
}
2 changes: 1 addition & 1 deletion src/EntityFramework.Relational/project.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
},
"dependencies": {
"EntityFramework.Core": "7.0.0-*",
"System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*"
"System.Diagnostics.DiagnosticSource": "4.0.0-beta-*"
},
"compile": "..\\Shared\\*.cs",
"namedResource": {
Loading

0 comments on commit 4de4695

Please sign in to comment.