|
20 | 20 | using Microsoft.Azure.WebJobs.Script.Config;
|
21 | 21 | using Microsoft.Azure.WebJobs.Script.Description;
|
22 | 22 | using Microsoft.Azure.WebJobs.Script.Diagnostics;
|
| 23 | +using Microsoft.Azure.WebJobs.Script.Diagnostics.OpenTelemetry; |
23 | 24 | using Microsoft.Azure.WebJobs.Script.Eventing;
|
24 | 25 | using Microsoft.Azure.WebJobs.Script.Extensions;
|
25 | 26 | using Microsoft.Azure.WebJobs.Script.Grpc.Eventing;
|
@@ -565,6 +566,12 @@ internal void ApplyCapabilities(IDictionary<string, string> capabilities, GrpcCa
|
565 | 566 | _isWorkerApplicationInsightsLoggingEnabled = true;
|
566 | 567 | }
|
567 | 568 |
|
| 569 | + if (bool.TryParse(_workerCapabilities.GetCapabilityState(RpcWorkerConstants.WorkerOpenTelemetryEnabled), out bool otelEnabled) && |
| 570 | + otelEnabled) |
| 571 | + { |
| 572 | + ScriptHost.WorkerOpenTelemetryEnabled = true; |
| 573 | + } |
| 574 | + |
568 | 575 | // If http proxying is enabled, we need to get the proxying endpoint of this worker
|
569 | 576 | var httpUri = _workerCapabilities.GetCapabilityState(RpcWorkerConstants.HttpUri);
|
570 | 577 | if (!string.IsNullOrEmpty(httpUri))
|
@@ -1670,29 +1677,47 @@ private void AddSample<T>(List<T> samples, T sample)
|
1670 | 1677 |
|
1671 | 1678 | private void AddAdditionalTraceContext(MapField<string, string> attributes, ScriptInvocationContext context)
|
1672 | 1679 | {
|
1673 |
| - // This is only applicable for AI agents running along side worker |
1674 |
| - if (_environment.IsApplicationInsightsAgentEnabled()) |
| 1680 | + bool isOtelEnabled = _scriptHostOptions?.Value.TelemetryMode == TelemetryMode.OpenTelemetry; |
| 1681 | + bool isAIEnabled = _environment.IsApplicationInsightsAgentEnabled(); |
| 1682 | + |
| 1683 | + if (isOtelEnabled || isAIEnabled) |
1675 | 1684 | {
|
1676 |
| - attributes[ScriptConstants.LogPropertyProcessIdKey] = Convert.ToString(_rpcWorkerProcess.Id); |
1677 | 1685 | if (context.FunctionMetadata.Properties.TryGetValue(ScriptConstants.LogPropertyHostInstanceIdKey, out var hostInstanceIdValue))
|
1678 | 1686 | {
|
1679 |
| - attributes[ScriptConstants.LogPropertyHostInstanceIdKey] = Convert.ToString(hostInstanceIdValue); |
1680 |
| - } |
1681 |
| - if (context.FunctionMetadata.Properties.TryGetValue(LogConstants.CategoryNameKey, out var categoryNameValue)) |
1682 |
| - { |
1683 |
| - attributes[LogConstants.CategoryNameKey] = Convert.ToString(categoryNameValue); |
| 1687 | + string id = Convert.ToString(hostInstanceIdValue); |
| 1688 | + |
| 1689 | + if (isOtelEnabled) |
| 1690 | + { |
| 1691 | + Activity.Current?.AddTag(ResourceSemanticConventions.FaaSInstance, id); |
| 1692 | + } |
| 1693 | + if (isAIEnabled) |
| 1694 | + { |
| 1695 | + attributes[ScriptConstants.LogPropertyHostInstanceIdKey] = id; |
| 1696 | + } |
1684 | 1697 | }
|
1685 |
| - string sessionid = Activity.Current?.GetBaggageItem(ScriptConstants.LiveLogsSessionAIKey); |
1686 |
| - if (!string.IsNullOrEmpty(sessionid)) |
| 1698 | + } |
| 1699 | + |
| 1700 | + if (isAIEnabled) |
| 1701 | + { |
| 1702 | + attributes[ScriptConstants.LogPropertyProcessIdKey] = Convert.ToString(_rpcWorkerProcess.Id); |
| 1703 | + attributes[ScriptConstants.OperationNameKey] = context.FunctionMetadata.Name; |
| 1704 | + string sessionId = Activity.Current?.GetBaggageItem(ScriptConstants.LiveLogsSessionAIKey); |
| 1705 | + if (!string.IsNullOrEmpty(sessionId)) |
1687 | 1706 | {
|
1688 |
| - attributes[ScriptConstants.LiveLogsSessionAIKey] = sessionid; |
| 1707 | + attributes[ScriptConstants.LiveLogsSessionAIKey] = sessionId; |
1689 | 1708 | }
|
1690 |
| - string operationName = context.FunctionMetadata.Name; |
1691 |
| - if (!string.IsNullOrEmpty(operationName)) |
| 1709 | + |
| 1710 | + if (context.FunctionMetadata.Properties.TryGetValue(LogConstants.CategoryNameKey, out var categoryNameValue)) |
1692 | 1711 | {
|
1693 |
| - attributes[ScriptConstants.OperationNameKey] = operationName; |
| 1712 | + attributes[LogConstants.CategoryNameKey] = Convert.ToString(categoryNameValue); |
1694 | 1713 | }
|
1695 | 1714 | }
|
| 1715 | + |
| 1716 | + if (isOtelEnabled) |
| 1717 | + { |
| 1718 | + Activity.Current?.AddTag(ResourceSemanticConventions.FaaSName, context.FunctionMetadata.Name); |
| 1719 | + Activity.Current?.AddTag(ResourceSemanticConventions.FaaSTrigger, OpenTelemetryConstants.ResolveTriggerType(context.FunctionMetadata?.Trigger?.Type)); |
| 1720 | + } |
1696 | 1721 | }
|
1697 | 1722 |
|
1698 | 1723 | private sealed class ExecutingInvocation : IDisposable
|
|
0 commit comments