예제 #1
0
        private void ActivateLogIdAndResource(string logId)
        {
            // Project ID of the project where the resource that is being monitored lives.
            string monitoredProjectId = null;
            // Project ID of the project where the entries are to be written.
            string            targetProjectId = null;
            MonitoredResource resource        = null;

            if (!DisableResourceTypeDetection)
            {
                resource = MonitoredResourceBuilder.FromPlatform(_platform);
                resource.Labels.TryGetValue("project_id", out monitoredProjectId);
            }

            targetProjectId = ProjectId?.Render(LogEventInfo.CreateNullEvent());

            if (monitoredProjectId == null)
            {
                // Either platform detection is disabled, or it detected an unknown platform.
                // So use the manually configured projectId and override the resource.
                monitoredProjectId = GaxPreconditions.CheckNotNull(targetProjectId, nameof(ProjectId));
                if (ResourceType == null)
                {
                    resource = new MonitoredResource {
                        Type = "global", Labels = { { "project_id", monitoredProjectId } }
                    };
                }
                else
                {
                    resource = new MonitoredResource
                    {
                        Type   = ResourceType,
                        Labels = { ResourceLabels.ToDictionary(x => x.Name, x => x.Layout.Render(LogEventInfo.CreateNullEvent())) }
                    };
                }
            }

            if (targetProjectId == null)
            {
                // If there was no configured projectId, then use the same as the monitored resoure.
                targetProjectId = monitoredProjectId;
            }

            _resource = resource;
            var logName = new LogName(targetProjectId, logId);

            _logName           = logName.ToString();
            _logNameToWrite    = logName;
            _traceResourcePath = !string.IsNullOrEmpty(targetProjectId) ? $"projects/{targetProjectId}/traces/" : null;
        }
예제 #2
0
        private void ActivateLogIdAndResource(string logId)
        {
            string            projectId = null;
            MonitoredResource resource  = null;

            if (!DisableResourceTypeDetection)
            {
                resource = MonitoredResourceBuilder.FromPlatform(_platform);
                resource.Labels.TryGetValue("project_id", out projectId);
            }

            if (projectId == null)
            {
                // Either platform detection is disabled, or it detected an unknown platform.
                // So use the manually configured projectId and override the resource.
                projectId = GaxPreconditions.CheckNotNull(ProjectId?.Render(LogEventInfo.CreateNullEvent()), nameof(ProjectId));
                if (ResourceType == null)
                {
                    resource = new MonitoredResource {
                        Type = "global", Labels = { { "project_id", projectId } }
                    };
                }
                else
                {
                    resource = new MonitoredResource {
                        Type   = ResourceType,
                        Labels = { ResourceLabels.ToDictionary(x => x.Name, x => x.Layout.Render(LogEventInfo.CreateNullEvent())) }
                    };
                }
            }

            _resource = resource;
            var logName = new LogName(projectId, logId);

            _logName        = logName.ToString();
            _logNameToWrite = LogNameOneof.From(logName);
        }