Unverified Commit 24d36f36 authored by Lemon's avatar Lemon Committed by GitHub

Fix issue#66 (#67)

parent 3e72e125
......@@ -9,10 +9,8 @@ namespace SkyWalking.Sample.AspNet.Controllers
{
public async Task<IHttpActionResult> Get()
{
// var httpClient = new HttpClient(new HttpTracingHandler());
// var values = await httpClient.GetStringAsync("http://localhost:5002/api/values");
var values = 1;
var httpClient = new HttpClient(new HttpTracingHandler());
var values = await httpClient.GetStringAsync("http://localhost:5001/api/values");
return Json(values);
}
}
......
......@@ -16,6 +16,7 @@
*
*/
using System.Collections.Generic;
using SkyWalking.Context.Trace;
namespace SkyWalking.Context
......@@ -29,6 +30,8 @@ namespace SkyWalking.Context
IContextSnapshot Capture { get; }
ISpan ActiveSpan { get; }
IDictionary<string,object> Properties { get; }
void Continued(IContextSnapshot snapshot);
......
......@@ -17,6 +17,7 @@
*/
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using SkyWalking.Boot;
......@@ -98,6 +99,8 @@ namespace SkyWalking.Context
public static IContextSnapshot Capture => _context.Value?.Capture;
public static IDictionary<string, object> ContextProperties => _context.Value?.Properties;
public static ISpan CreateEntrySpan(string operationName, IContextCarrier carrier)
{
var samplingService = ServiceManager.Instance.GetService<SamplingService>();
......
......@@ -16,6 +16,7 @@
*
*/
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using SkyWalking.Context.Trace;
......@@ -49,6 +50,8 @@ namespace SkyWalking.Context
}
}
public IDictionary<string, object> Properties { get; } = new Dictionary<string, object>();
public void Continued(IContextSnapshot snapshot)
{
}
......@@ -83,6 +86,13 @@ namespace SkyWalking.Context
if (_spans.Count == 0)
{
ListenerManager.NotifyFinish(this);
foreach (var item in Properties)
{
if (item.Value is IDisposable disposable)
{
disposable.Dispose();
}
}
}
}
......
......@@ -121,6 +121,8 @@ namespace SkyWalking.Context
public IContextSnapshot Capture => InternalCapture();
public ISpan ActiveSpan => InternalActiveSpan();
public IDictionary<string, object> Properties { get; } = new Dictionary<string, object>();
public void Continued(IContextSnapshot snapshot)
{
......@@ -288,6 +290,14 @@ namespace SkyWalking.Context
}
ListenerManager.NotifyFinish(finishedSegment);
foreach (var item in Properties)
{
if (item.Value is IDisposable disposable)
{
disposable.Dispose();
}
}
}
private ISpan InternalActiveSpan()
......
......@@ -32,6 +32,7 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
{
public class EntityFrameworkCoreDiagnosticProcessor : ITracingDiagnosticProcessor
{
private const string TRACE_ORM = "TRACE_ORM";
private Func<CommandEventData, string> _operationNameResolver;
private readonly IEfCoreSpanFactory _efCoreSpanFactory;
......@@ -69,12 +70,14 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
Tags.DbInstance.Set(span, eventData.Command.Connection.Database);
Tags.DbStatement.Set(span, eventData.Command.CommandText);
Tags.DbBindVariables.Set(span, BuildParameterVariables(eventData.Command.Parameters));
ContextManager.ContextProperties[TRACE_ORM] = true;
}
[DiagnosticName("Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted")]
public void CommandExecuted()
{
ContextManager.StopSpan();
ContextManager.ContextProperties.Remove(TRACE_ORM);
}
[DiagnosticName("Microsoft.EntityFrameworkCore.Database.Command.CommandError")]
......@@ -92,6 +95,7 @@ namespace SkyWalking.Diagnostics.EntityFrameworkCore
}
span.ErrorOccurred();
ContextManager.StopSpan(span);
ContextManager.ContextProperties.Remove(TRACE_ORM);
}
private string BuildParameterVariables(DbParameterCollection dbParameters)
......
......@@ -28,6 +28,7 @@ namespace SkyWalking.Diagnostics.SqlClient
{
public class SqlClientDiagnosticProcessor : ITracingDiagnosticProcessor
{
private const string TRACE_ORM = "TRACE_ORM";
public string ListenerName { get; } = SqlClientDiagnosticStrings.DiagnosticListenerName;
private static string ResolveOperationName(SqlCommand sqlCommand)
......@@ -39,6 +40,10 @@ namespace SkyWalking.Diagnostics.SqlClient
[DiagnosticName(SqlClientDiagnosticStrings.SqlBeforeExecuteCommand)]
public void BeforeExecuteCommand([Property(Name = "Command")] SqlCommand sqlCommand)
{
if (ContextManager.ContextProperties.ContainsKey(TRACE_ORM))
{
return;
}
var peer = sqlCommand.Connection.DataSource;
var span = ContextManager.CreateExitSpan(ResolveOperationName(sqlCommand), peer);
span.SetLayer(SpanLayer.DB);
......@@ -52,12 +57,20 @@ namespace SkyWalking.Diagnostics.SqlClient
[DiagnosticName(SqlClientDiagnosticStrings.SqlAfterExecuteCommand)]
public void AfterExecuteCommand()
{
if (ContextManager.ContextProperties.ContainsKey(TRACE_ORM))
{
return;
}
ContextManager.StopSpan();
}
[DiagnosticName(SqlClientDiagnosticStrings.SqlErrorExecuteCommand)]
public void ErrorExecuteCommand([Property(Name = "Exception")] Exception ex)
{
if (ContextManager.ContextProperties.ContainsKey(TRACE_ORM))
{
return;
}
var span = ContextManager.ActiveSpan;
span?.ErrorOccurred();
span?.Log(ex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment