private void OnStop() { var activity = Activity.Current; if (activity is null) { Logger.Trace()?.Log("Current activity is null - exiting"); return; } if (!_processingSegments.TryRemove(activity.Id, out var span)) { Logger.Trace()?.Log( "Could not find segment for activity {ActivityId} in tracked segments", activity.Id); return; } if (span.Context.Destination is null) { var urlTag = activity.Tags.FirstOrDefault(t => t.Key == "url").Value; if (BlobUrl.TryCreate(urlTag, out var blobUrl)) { span.Name += $" {blobUrl.ResourceName}"; SetDestination(span, blobUrl); } } span.Outcome = Outcome.Success; span.End(); }
private static void SetDestination(ISpan span, BlobUrl blobUrl) => span.Context.Destination = new Destination { Address = blobUrl.FullyQualifiedNamespace, Service = new Destination.DestinationService { Resource = $"{AzureBlobStorage.SubType}/{blobUrl.StorageAccountName}" } };
public static bool TryCreate(string url, out BlobUrl blobUrl) { if (Uri.TryCreate(url, UriKind.Absolute, out var uri)) { blobUrl = new BlobUrl(uri); return(true); } blobUrl = null; return(false); }
private void OnStart(KeyValuePair <string, object> kv, string action) { var currentSegment = ApmAgent.GetCurrentExecutionSegment(); if (currentSegment is null) { Logger.Trace()?.Log("No current transaction or span - exiting"); return; } if (!(kv.Value is Activity activity)) { Logger.Trace()?.Log("Value is not an activity - exiting"); return; } var urlTag = activity.Tags.FirstOrDefault(t => t.Key == "url").Value; var blobUrl = new BlobUrl(urlTag); var spanName = $"{AzureBlobStorage.SpanName} {action} {blobUrl.ResourceName}"; var span = currentSegment.StartSpan(spanName, ApiConstants.TypeStorage, AzureBlobStorage.SubType, action); if (span is Span realSpan) { realSpan.InstrumentationFlag = InstrumentationFlag.Azure; } span.Context.Destination = new Destination { Address = blobUrl.FullyQualifiedNamespace, Service = new Destination.DestinationService { Name = AzureBlobStorage.SubType, Resource = $"{AzureBlobStorage.SubType}/{blobUrl.StorageAccountName}", Type = ApiConstants.TypeStorage } }; if (!_processingSegments.TryAdd(activity.Id, span)) { Logger.Trace() ?.Log( "Could not add {Action} span {SpanId} for activity {ActivityId} to tracked spans", action, span.Id, activity.Id); } }
private void OnStart(KeyValuePair <string, object> kv, string action) { var currentSegment = ApmAgent.GetCurrentExecutionSegment(); if (currentSegment is null) { Logger.Trace()?.Log("No current transaction or span - exiting"); return; } if (!(kv.Value is Activity activity)) { Logger.Trace()?.Log("Value is not an activity - exiting"); return; } var urlTag = activity.Tags.FirstOrDefault(t => t.Key == "url").Value; var spanName = BlobUrl.TryCreate(urlTag, out var blobUrl) ? $"{AzureBlobStorage.SpanName} {action} {blobUrl.ResourceName}" : $"{AzureBlobStorage.SpanName} {action}"; var span = currentSegment.StartSpan(spanName, ApiConstants.TypeStorage, AzureBlobStorage.SubType, action, true); if (span is Span realSpan) { realSpan.InstrumentationFlag = InstrumentationFlag.Azure; } if (blobUrl != null) { SetDestination(span, blobUrl); } if (!_processingSegments.TryAdd(activity.Id, span)) { Logger.Trace() ?.Log( "Could not add {Action} span {SpanId} for activity {ActivityId} to tracked spans", action, span.Id, activity.Id); } }
public ISpan StartSpan(IApmAgent agent, string method, Uri requestUrl, Func <string, string> headerGetter) { var blobUrl = new BlobUrl(requestUrl); string action = null; switch (method) { case "DELETE": action = "Delete"; break; case "GET": if (requestUrl.Query.Contains("restype=container")) { if (requestUrl.Query.Contains("comp=list")) { action = "ListBlobs"; } else if (requestUrl.Query.Contains("comp=acl")) { action = "GetAcl"; } else { action = "GetProperties"; } } else { if (requestUrl.Query.Contains("comp=metadata")) { action = "GetMetadata"; } else if (requestUrl.Query.Contains("comp=list")) { action = "ListContainers"; } else if (requestUrl.Query.Contains("comp=tags")) { action = requestUrl.Query.Contains("where=") ? "FindTags" : "GetTags"; } else { action = "Download"; } } break; case "HEAD": if (requestUrl.Query.Contains("comp=metadata")) { action = "GetMetadata"; } else if (requestUrl.Query.Contains("comp=acl")) { action = "GetAcl"; } else { action = "GetProperties"; } break; case "POST": if (requestUrl.Query.Contains("comp=batch")) { action = "Batch"; } else if (requestUrl.Query.Contains("comp=query")) { action = "Query"; } break; case "PUT": if (!string.IsNullOrEmpty(headerGetter("x-ms-copy-source"))) { action = "Copy"; } else if (requestUrl.Query.Contains("comp=copy")) { action = "Abort"; } else if (!string.IsNullOrEmpty(headerGetter("x-ms-blob-type")) || requestUrl.Query.Contains("comp=block") || requestUrl.Query.Contains("comp=blocklist") || requestUrl.Query.Contains("comp=page") || requestUrl.Query.Contains("comp=appendblock")) { action = "Upload"; } else if (requestUrl.Query.Contains("comp=metadata")) { action = "SetMetadata"; } else if (requestUrl.Query.Contains("comp=acl")) { action = "SetAcl"; } else if (requestUrl.Query.Contains("comp=properties")) { action = "SetProperties"; } else if (requestUrl.Query.Contains("comp=lease")) { action = "Lease"; } else if (requestUrl.Query.Contains("comp=snapshot")) { action = "Snapshot"; } else if (requestUrl.Query.Contains("comp=undelete")) { action = "Undelete"; } else if (requestUrl.Query.Contains("comp=tags")) { action = "SetTags"; } else if (requestUrl.Query.Contains("comp=tier")) { action = "SetTier"; } else if (requestUrl.Query.Contains("comp=expiry")) { action = "SetExpiry"; } else if (requestUrl.Query.Contains("comp=seal")) { action = "Seal"; } else { action = "Create"; } break; } if (action is null) { return(null); } var name = $"{AzureBlobStorage.SpanName} {action} {blobUrl.ResourceName}"; var span = ExecutionSegmentCommon.StartSpanOnCurrentExecutionSegment(agent, name, ApiConstants.TypeStorage, AzureBlobStorage.SubType, InstrumentationFlag.Azure, true); span.Action = action; span.Context.Destination = new Destination { Address = blobUrl.FullyQualifiedNamespace, Service = new Destination.DestinationService { Name = AzureBlobStorage.SubType, Resource = $"{AzureBlobStorage.SubType}/{blobUrl.ResourceName}", Type = ApiConstants.TypeStorage } }; if (span is Span realSpan) { realSpan.InstrumentationFlag = InstrumentationFlag.Azure; } return(span); }