private async Task <byte[]> HandleAndTrackRequestAsync(ServiceRemotingMessageHeaders messageHeaders, Func <Task <byte[]> > doHandleRequest) { // set service context ServiceFabricServiceContext.Set(serviceContext); // create logger per operation ILogger logger = LoggingContext.CreateLogger <CorrelatingRemotingMessageHandler>(); // Do our best effort in setting the request name. string methodName = methodNameProvider.GetMethodName(messageHeaders.InterfaceId, messageHeaders.MethodId); // Weird case, we couldn't find the method in the map. Just use the numerical id as the method name if (string.IsNullOrEmpty(methodName)) { methodName = messageHeaders.MethodId.ToString(); } // get service & operation names Uri operationUri = ServiceFabricHelper.MakeOperationUri(serviceContext.ServiceName, methodName); string operationName = ServiceFabricHelper.MakeOperationName(serviceContext.ServiceName, methodName); string serviceName = ServiceFabricHelper.GetServiceName(serviceContext.ServiceName); // create request activity Activity activity = new Activity(operationName); if (messageHeaders.TryGetHeaderValue(ServiceRemotingStrings.ParentIdHeaderName, out string parentId)) { activity.SetParentId(parentId); } // get parent operation source messageHeaders.TryGetHeaderValue(ServiceRemotingStrings.SourceHeaderName, out string source); // set activity baggage if (messageHeaders.TryGetHeaderValue(ServiceRemotingStrings.CorrelationContextHeaderName, out byte[] correlationBytes))
public void Initialize(ITelemetry telemetry) { if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName)) { ServiceFabricServiceContext sfServiceContext = ServiceFabricServiceContext.Current; if (sfServiceContext?.Name != null) { telemetry.Context.Cloud.RoleName = sfServiceContext.Name; } } }
protected override async Task RunAsync(CancellationToken cancellationToken) { try { // init service fabric context ServiceFabricServiceContext.Set(Context); await Task.CompletedTask; } catch (Exception ex) { LoggingContext.CreateLogger <WebApi>() .LogError(ex, "Service exception in RunAsync"); } }
protected override async Task RunAsync(CancellationToken cancellationToken) { try { // init service fabric context ServiceFabricServiceContext.Set(Context); // start a service bus receiver sbReceiverClient.Receive <QueueRequest>(ProcessMessagesAsync); await Task.CompletedTask; } catch (Exception ex) { LoggingContext.CreateLogger <ServiceBusDependencyReceiver>() .LogError(ex, "Service exception in RunAsync"); } }
protected override async Task RunAsync(CancellationToken cancellationToken) { try { // init service fabric context ServiceFabricServiceContext.Set(Context); // initailize DocumentDb client factory var config = new DocumentDbConnectionConfig(); documentDbClientFactory = new DocumentDbClientFactory(config); // initilize the DOcument database & collection await UserCollectionInitializer.Initialize(documentDbClientFactory); await Task.CompletedTask; } catch (Exception ex) { LoggingContext.CreateLogger <DocumentDbDependency>() .LogError(ex, "Service exception in RunAsync"); } }
public void Initialize(ITelemetry telemetry) { ServiceFabricServiceContext sfServiceContext = ServiceFabricServiceContext.Current; if (sfServiceContext != null) { if (sfServiceContext.Type != null && !telemetry.Context.Properties.ContainsKey(ServiceTypeName)) { telemetry.Context.Properties.Add(ServiceTypeName, sfServiceContext.Type); } if (sfServiceContext.Name != null && !telemetry.Context.Properties.ContainsKey(ServiceName)) { telemetry.Context.Properties.Add(ServiceName, sfServiceContext.Name); } if (sfServiceContext.Uri != null && !telemetry.Context.Properties.ContainsKey(ServiceUri)) { telemetry.Context.Properties.Add(ServiceUri, sfServiceContext.Uri.ToString()); } if (sfServiceContext.InstanceId != null && !telemetry.Context.Properties.ContainsKey(InstanceId)) { telemetry.Context.Properties.Add(InstanceId, sfServiceContext.InstanceId); } if (sfServiceContext.ReplicaId != null && !telemetry.Context.Properties.ContainsKey(ReplicaId)) { telemetry.Context.Properties.Add(ReplicaId, sfServiceContext.ReplicaId); } if (sfServiceContext.PartitionId != null && !telemetry.Context.Properties.ContainsKey(PartitionId)) { telemetry.Context.Properties.Add(PartitionId, sfServiceContext.PartitionId); } } }
public override async Task Invoke(IOwinContext context) { ServiceFabricServiceContext.Set(this.serviceContext); await Next.Invoke(context); }