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

Public cleanup #78

Merged
merged 4 commits into from
Jan 28, 2019
Merged
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
3 changes: 3 additions & 0 deletions sample/SampleAspNetCoreApp/SampleAspNetCoreApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\elasticapm.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Elastic.Apm.AspNetCore/ApmMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
namespace Elastic.Apm.AspNetCore
{
// ReSharper disable once ClassNeverInstantiated.Global
public class ApmMiddleware
internal class ApmMiddleware
{
private readonly RequestDelegate _next;
private readonly ITracer _tracer;
private readonly Tracer _tracer;

public ApmMiddleware(RequestDelegate next, ITracer tracer)
public ApmMiddleware(RequestDelegate next, Tracer tracer)
{
_next = next;
_tracer = tracer;
}

public async Task InvokeAsync(HttpContext context)
{
var transaction = _tracer.StartTransaction($"{context.Request.Method} {context.Request.Path}",
var transaction = _tracer.StartTransactionInternal($"{context.Request.Method} {context.Request.Path}",
ApiConstants.TypeRequest);
gregkalapos marked this conversation as resolved.
Show resolved Hide resolved

transaction.Context.Request = new Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Elastic.Apm.AspNetCore.Config
/// An agent-config provider based on Microsoft.Extensions.Configuration.IConfiguration.
/// It uses environment variables as fallback
/// </summary>
public class MicrosoftExtensionsConfig : AbstractConfigurationReader, IConfigurationReader
internal class MicrosoftExtensionsConfig : AbstractConfigurationReader, IConfigurationReader
{
private readonly IConfiguration _configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

namespace Elastic.Apm.AspNetCore.DiagnosticListener
{
public class AspNetCoreDiagnosticListener : IDiagnosticListener
internal class AspNetCoreDiagnosticListener : IDiagnosticListener
{
private readonly AbstractLogger _logger;

public AspNetCoreDiagnosticListener(IApmAgent agent) => _logger = agent.Logger;

public string Name => "Microsoft.AspNetCore";
public IDisposable SourceSubscription { get; set; }

public void OnCompleted() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ namespace Elastic.Apm.EntityFrameworkCore
{
internal class EfCoreDiagnosticListener : IDiagnosticListener
{
private readonly ConcurrentDictionary<Guid, ISpan> _spans = new ConcurrentDictionary<Guid, ISpan>();
private readonly ConcurrentDictionary<Guid, Span> _spans = new ConcurrentDictionary<Guid, Span>();

public EfCoreDiagnosticListener(IApmAgent agent) => Logger = agent.Logger;

private AbstractLogger Logger { get; }

public string Name => "Microsoft.EntityFrameworkCore";
public IDisposable SourceSubscription { get; set; }

public void OnCompleted() { }

Expand All @@ -32,7 +31,7 @@ public void OnNext(KeyValuePair<string, object> kv)
case string k when k == RelationalEventId.CommandExecuting.Name && Agent.TransactionContainer.Transactions.Value != null:
if (kv.Value is CommandEventData commandEventData)
{
var newSpan = Agent.TransactionContainer.Transactions.Value.StartSpan(
var newSpan = Agent.TransactionContainer.Transactions.Value.StartSpanInternal(
commandEventData.Command.CommandText, ApiConstants.TypeDb);

_spans.TryAdd(commandEventData.CommandId, newSpan);
Expand Down
2 changes: 2 additions & 0 deletions src/Elastic.Apm/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public ApmAgent(AgentComponents agentComponents) =>

internal readonly CompositeDisposable Disposables = new CompositeDisposable();
public void Dispose() => Disposables?.Dispose();

internal Tracer TracerInternal => Tracer as Tracer;
}

public static class Agent
Expand Down
6 changes: 4 additions & 2 deletions src/Elastic.Apm/AgentComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AgentComponents(
ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(Logger);
Service = service ?? Service.GetDefaultService(ConfigurationReader);
PayloadSender = payloadSender ?? new PayloadSender(Logger, ConfigurationReader);
Tracer = new Tracer(Logger, Service, PayloadSender);
TracerInternal = new Tracer(Logger, Service, PayloadSender);
TransactionContainer = new TransactionContainer();
}

Expand All @@ -28,7 +28,9 @@ public AgentComponents(

public IConfigurationReader ConfigurationReader { get; }

public ITracer Tracer { get; }
public ITracer Tracer => TracerInternal;

internal Tracer TracerInternal { get; }

internal TransactionContainer TransactionContainer { get; }

Expand Down
30 changes: 30 additions & 0 deletions src/Elastic.Apm/Api/IError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;

namespace Elastic.Apm.Api
{
public interface IError
{
List<IErrorDetail> Errors { get; set; }
}

public interface IErrorDetail
{
string Culprit { get; set; }
ICapturedException Exception { get; set; }
Guid Id { get; }
}

public interface ICapturedException
{
/// <summary>
/// The exception message, see: <see cref="Exception.Message"/>
/// </summary>
string Message { get; set; }

/// <summary>
/// The type of the exception class
/// </summary>
string Type { get; set; }
}
}
28 changes: 0 additions & 28 deletions src/Elastic.Apm/Api/ISpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ public interface ISpan
/// </summary>
string Action { get; set; }

/// <summary>
/// Any other arbitrary data captured by the agent, optionally provided by the user.
/// </summary>
IContext Context { get; }

/// <summary>
/// The duration of the span.
/// If it's not set (its HasValue property is false) then the value
Expand All @@ -36,8 +31,6 @@ public interface ISpan
/// </summary>
string Name { get; set; }

List<Stacktrace> StackTrace { get; set; }

/// <summary>
/// Offset relative to the transaction's timestamp identifying the start of the span, in milliseconds.
/// </summary>
Expand Down Expand Up @@ -86,25 +79,4 @@ public interface ISpan
/// </summary>
void End();
}

public interface IContext
{
IDb Db { get; set; }
IHttp Http { get; set; }
Dictionary<string, string> Tags { get; }
}

public interface IDb
{
string Instance { get; set; }
string Statement { get; set; }
string Type { get; set; }
}

public interface IHttp
{
string Method { get; set; }
int StatusCode { get; set; }
string Url { get; set; }
}
}
10 changes: 0 additions & 10 deletions src/Elastic.Apm/Api/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ namespace Elastic.Apm.Api
{
public interface ITransaction
{
/// <summary>
/// Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user.
/// </summary>
Context Context { get; }

/// <summary>
/// The duration of the transaction.
/// If it's not set (its HasValue property is false) then the value
Expand All @@ -35,16 +30,11 @@ public interface ITransaction
/// <value>The result.</value>
string Result { get; set; }

//TODO: probably won't need with intake v2
ISpan[] Spans { get; }

/// <summary>
/// A flat mapping of user-defined tags with string values.
/// </summary>
Dictionary<string, string> Tags { get; }

string Timestamp { get; }

/// <summary>
/// The type of the transaction.
/// Example: 'request'
Expand Down
4 changes: 3 additions & 1 deletion src/Elastic.Apm/Api/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public Tracer(AbstractLogger logger, Service service, IPayloadSender payloadSend
_sender = payloadSender;
}


public ITransaction StartTransaction(string name, string type)
=> StartTransactionInternal(name, type);

internal Transaction StartTransactionInternal(string name, string type)
{
var retVal = new Transaction(_logger, name, type, _sender)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm/Config/EnvironmentConfigurationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Elastic.Apm.Config
{
public class EnvironmentConfigurationReader : AbstractConfigurationReader, IConfigurationReader
internal class EnvironmentConfigurationReader : AbstractConfigurationReader, IConfigurationReader
{
internal const string Origin = "environment";

Expand Down
10 changes: 5 additions & 5 deletions src/Elastic.Apm/DiagnosticListeners/HttpDiagnosticListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@

namespace Elastic.Apm.DiagnosticListeners
{
/// <inheritdoc />
/// <summary>
/// Captures web requests initiated by <see cref="System.Net.Http.HttpClient" />
/// Captures web requests initiated by <see cref="T:System.Net.Http.HttpClient" />
/// </summary>
public class HttpDiagnosticListener : IDiagnosticListener
internal class HttpDiagnosticListener : IDiagnosticListener
{

/// <summary>
/// Keeps track of ongoing requests
/// </summary>
internal readonly ConcurrentDictionary<HttpRequestMessage, ISpan> ProcessingRequests = new ConcurrentDictionary<HttpRequestMessage, ISpan>();
internal readonly ConcurrentDictionary<HttpRequestMessage, Span> ProcessingRequests = new ConcurrentDictionary<HttpRequestMessage, Span>();

public HttpDiagnosticListener(IApmAgent components) =>
(Logger, ConfigurationReader) = (components.Logger, components.ConfigurationReader);
Expand All @@ -32,7 +33,6 @@ public HttpDiagnosticListener(IApmAgent components) =>
private IConfigurationReader ConfigurationReader { get; }

public string Name => "HttpHandlerDiagnosticListener";
public IDisposable SourceSubscription { get; set; }

public void OnCompleted() { }

Expand Down Expand Up @@ -61,7 +61,7 @@ public void OnNext(KeyValuePair<string, object> kv)

transaction = Agent.TransactionContainer.Transactions.Value;

var span = transaction.StartSpan($"{request?.Method} {request?.RequestUri?.Host}", ApiConstants.TypeExternal,
var span = transaction.StartSpanInternal($"{request?.Method} {request?.RequestUri?.Host}", ApiConstants.TypeExternal,
ApiConstants.SubtypeHttp);

if (ProcessingRequests.TryAdd(request, span))
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm/DiagnosticSource/DiagnosticInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class DiagnosticInitializer : IObserver<DiagnosticListener>, IDisposabl
private readonly IEnumerable<IDiagnosticListener> _listeners;
private IDisposable _sourceSubscription;

public DiagnosticInitializer(IEnumerable<IDiagnosticListener> listeners) => _listeners = listeners;
internal DiagnosticInitializer(IEnumerable<IDiagnosticListener> listeners) => _listeners = listeners;

public void OnCompleted() { }

Expand Down
8 changes: 1 addition & 7 deletions src/Elastic.Apm/DiagnosticSource/IDiagnosticListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ namespace Elastic.Apm.DiagnosticSource
/// Common interface for every diagnostic listener
/// The DiagnosticInitializer works through this interface with the different listeners
/// </summary>
public interface IDiagnosticListener : IObserver<KeyValuePair<string, object>>
internal interface IDiagnosticListener : IObserver<KeyValuePair<string, object>>
{
/// <summary>
/// Represents the component associated with the event.
/// </summary>
/// <value>The name.</value>
string Name { get; }

/// <summary>
/// Reference to the source subscription.
/// This is set by <see cref="DiagnosticInitializer"/>
/// </summary>
IDisposable SourceSubscription { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Elastic.Apm/Helpers/StacktraceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace Elastic.Apm.Helpers
{
public static class StacktraceHelper
internal static class StacktraceHelper
{
/// <summary>
/// Turns a System.Diagnostic.StackFrame[] into a <see cref="Stacktrace" /> list which can be reported to the APM Server
/// </summary>
/// <param name="capturingFor">Just for logging.</param>
/// <returns>A prepared List that can be passed to the APM server</returns>
public static List<Stacktrace> GenerateApmStackTrace(StackFrame[] frames, AbstractLogger logger, string capturingFor)
internal static List<Stacktrace> GenerateApmStackTrace(StackFrame[] frames, AbstractLogger logger, string capturingFor)
{
var retVal = new List<Stacktrace>(frames.Length);

Expand Down
10 changes: 5 additions & 5 deletions src/Elastic.Apm/Logging/AbstractLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class AbstractLogger
/// they need to write it (e.g. into a file, to the console)
/// </summary>
/// <param name="logline">This line that must be logged - it already contains the prefix and the loglevel</param>
protected abstract void PrintLogline(string logline);
protected abstract void PrintLogLine(string logLine);
gregkalapos marked this conversation as resolved.
Show resolved Hide resolved

private string GetPrefixString(LogLevel logLevel, string prefix) =>
string.IsNullOrWhiteSpace(prefix) ? $"{logLevel.ToString()} " : $"{logLevel.ToString()} {prefix}: ";
Expand All @@ -25,25 +25,25 @@ private string GetPrefixString(LogLevel logLevel, string prefix) =>
internal void LogInfo(string info) => LogInfo(null, info);
internal void LogInfo(string prefix, string info)
{
if (LogLevel >= LogLevel.Info) PrintLogline($"{GetPrefixString(LogLevel.Info, prefix)}{info}");
if (LogLevel >= LogLevel.Info) PrintLogLine($"{GetPrefixString(LogLevel.Info, prefix)}{info}");
}

internal void LogWarning(string warning) => LogWarning(null, warning);
internal void LogWarning(string prefix, string warning)
{
if (LogLevel >= LogLevel.Warning) PrintLogline($"{GetPrefixString(LogLevel.Warning, prefix)}{warning}");
if (LogLevel >= LogLevel.Warning) PrintLogLine($"{GetPrefixString(LogLevel.Warning, prefix)}{warning}");
}

internal void LogError(string error) => LogError(null, error);
internal void LogError(string prefix, string error)
{
if (LogLevel >= LogLevel.Error) PrintLogline($"{GetPrefixString(LogLevel.Error, prefix)}{error}");
if (LogLevel >= LogLevel.Error) PrintLogLine($"{GetPrefixString(LogLevel.Error, prefix)}{error}");
}

internal void LogDebug(string debug) => LogDebug(null, debug);
internal void LogDebug(string prefix, string debug)
{
if (LogLevel >= LogLevel.Debug) PrintLogline($"{GetPrefixString(LogLevel.Debug, prefix)}{debug}");
if (LogLevel >= LogLevel.Debug) PrintLogLine($"{GetPrefixString(LogLevel.Debug, prefix)}{debug}");
}
}
}
6 changes: 3 additions & 3 deletions src/Elastic.Apm/Logging/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace Elastic.Apm.Logging
{
internal class ConsoleLogger : AbstractLogger
{
protected ConsoleLogger(LogLevel level) : base(level) { }
private ConsoleLogger(LogLevel level) : base(level) { }

protected override void PrintLogline(string logline) => Console.WriteLine(logline);
protected override void PrintLogLine(string logLine) => Console.WriteLine(logLine);

public static ConsoleLogger Instance { get; } = new ConsoleLogger(LogLevelDefault);
internal static ConsoleLogger Instance { get; } = new ConsoleLogger(LogLevelDefault);
}
}
2 changes: 1 addition & 1 deletion src/Elastic.Apm/Model/Payload/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Elastic.Apm.Model.Payload
{
public class Context
internal class Context
{
public Request Request { get; set; }

Expand Down
Loading