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

LoggerRequest should provide the original property #518

Closed
1 of 4 tasks
saber-wang opened this issue Sep 28, 2022 · 1 comment
Closed
1 of 4 tasks

LoggerRequest should provide the original property #518

saber-wang opened this issue Sep 28, 2022 · 1 comment
Assignees
Milestone

Comments

@saber-wang
Copy link

saber-wang commented Sep 28, 2022

Please answer these questions before submitting your issue.

  • Why do you submit this issue?
  • Question or discussion
  • Bug
  • Requirement
  • Feature or performance improvement

Requirement or improvement

  • Please describe about your requirements or improvement suggestions.
    Example:
    public class LoggerRequest
    {
        public string Message{ get; set; }

        public Dictionary<string, object> Tags{ get; set; }

        public LoggerSegmentReference SegmentReference { get; set; }

        public long Date { get; set; }
    }

This will allow custom logs to be processed without overwriting LoggerReporter
Example:

        public async Task ReportAsync(IReadOnlyCollection<LoggerRequest> loggerRequests,
            CancellationToken cancellationToken = default)
        {
            if (!_connectionManager.Ready)
            {
                return;
            }

            var connection = _connectionManager.GetConnection();
            try
            {
                var stopwatch = Stopwatch.StartNew();
                var client = new LogReportService.LogReportServiceClient(connection);
                using (var asyncClientStreamingCall = client.collect(_grpcConfig.GetMeta(),
                           _grpcConfig.GetReportTimeout(), cancellationToken))
                {
                    foreach (var loggerRequest in loggerRequests)
                    {
                        var logBody = new LogData()
                        {
                            TraceContext = new TraceContext()
                            {
                                TraceId = loggerRequest.SegmentReference?.TraceId ?? string.Empty,
                                TraceSegmentId = loggerRequest.SegmentReference?.SegmentId ?? string.Empty,
                                //SpanId=item.Segment
                            },
                            Timestamp = loggerRequest.Date,
                            Service = _instrumentConfig.ServiceName,
                            ServiceInstance = _instrumentConfig.ServiceInstanceName,
                            Endpoint = "",
                            Body = new LogDataBody()
                            {
                                Type = "text",
                                Text = new TextLog()
                                {
                                    Text = Message,
                                },
                            },
                         Tags=...//todo loggerRequest.Tags 
                        };
                        await asyncClientStreamingCall.RequestStream.WriteAsync(logBody);
                    }

                    await asyncClientStreamingCall.RequestStream.CompleteAsync();
                    await asyncClientStreamingCall.ResponseAsync;

                    stopwatch.Stop();
                    _logger.Information($"Report {loggerRequests.Count} logs. cost: {stopwatch.Elapsed}s");
                }
            }
            catch (IOException ex)
            {
                _logger.Error("Report trace segment fail.", ex);
                _connectionManager.Failure(ex);
            }
            catch (Exception ex)
            {
                _logger.Error("Report trace segment fail.", ex);
            }
        }
@liuhaoyang liuhaoyang self-assigned this Oct 11, 2022
@liuhaoyang liuhaoyang modified the milestones: 2.1.0, 2.2.0 Oct 11, 2022
@wu-sheng
Copy link
Member

wu-sheng commented Mar 8, 2023

@liuhaoyang Are you going to finish this?

inversionhourglass added a commit to inversionhourglass/SkyAPM-dotnet that referenced this issue Mar 9, 2023
inversionhourglass added a commit to inversionhourglass/SkyAPM-dotnet that referenced this issue Mar 9, 2023
@saber-wang saber-wang mentioned this issue Mar 21, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants