From 72fefeb5c6fe57d1d3d83ee030c0be7cd51d3259 Mon Sep 17 00:00:00 2001 From: RassK Date: Fri, 19 Apr 2024 14:44:18 +0300 Subject: [PATCH 01/15] Change AccountService from go to dotnet (auto) --- .../AccountingService.csproj | 29 +++++ src/accountingservice/AccountingService.sln | 25 ++++ src/accountingservice/Consumer.cs | 89 +++++++++++++ src/accountingservice/Dockerfile | 64 ++++----- src/accountingservice/Helpers.cs | 31 +++++ src/accountingservice/Log.cs | 13 ++ src/accountingservice/Program.cs | 21 +++ src/accountingservice/README.md | 18 +-- src/accountingservice/kafka/consumer.go | 77 ----------- .../kafka/trace_interceptor.go | 62 --------- src/accountingservice/main.go | 123 ------------------ src/accountingservice/tools.go | 17 --- 12 files changed, 243 insertions(+), 326 deletions(-) create mode 100644 src/accountingservice/AccountingService.csproj create mode 100644 src/accountingservice/AccountingService.sln create mode 100644 src/accountingservice/Consumer.cs create mode 100644 src/accountingservice/Helpers.cs create mode 100644 src/accountingservice/Log.cs create mode 100644 src/accountingservice/Program.cs delete mode 100644 src/accountingservice/kafka/consumer.go delete mode 100644 src/accountingservice/kafka/trace_interceptor.go delete mode 100644 src/accountingservice/main.go delete mode 100644 src/accountingservice/tools.go diff --git a/src/accountingservice/AccountingService.csproj b/src/accountingservice/AccountingService.csproj new file mode 100644 index 0000000000..c1f2bae683 --- /dev/null +++ b/src/accountingservice/AccountingService.csproj @@ -0,0 +1,29 @@ + + + + Exe + net8.0 + enable + enable + Linux + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/src/accountingservice/AccountingService.sln b/src/accountingservice/AccountingService.sln new file mode 100644 index 0000000000..e7ee43df26 --- /dev/null +++ b/src/accountingservice/AccountingService.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34701.34 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccountingService", "AccountingService.csproj", "{C66C35E2-DF04-4DCF-8F6A-87B6D6433FF6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C66C35E2-DF04-4DCF-8F6A-87B6D6433FF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C66C35E2-DF04-4DCF-8F6A-87B6D6433FF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C66C35E2-DF04-4DCF-8F6A-87B6D6433FF6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C66C35E2-DF04-4DCF-8F6A-87B6D6433FF6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6340CDDC-E917-4532-A056-5526E0A7BDDA} + EndGlobalSection +EndGlobal diff --git a/src/accountingservice/Consumer.cs b/src/accountingservice/Consumer.cs new file mode 100644 index 0000000000..5e6182e8aa --- /dev/null +++ b/src/accountingservice/Consumer.cs @@ -0,0 +1,89 @@ +using Confluent.Kafka; +using Confluent.Kafka.SyncOverAsync; +using Confluent.SchemaRegistry.Serdes; +using Microsoft.Extensions.Logging; +using Oteldemo; + +namespace AccountingService; + +internal class Consumer : IDisposable +{ + private const string TopicName = "orders"; + + private ILogger _logger; + private IConsumer _consumer; + private bool _isListening; + + public Consumer(ILogger logger) + { + _logger = logger; + + var servers = Environment.GetEnvironmentVariable("KAFKA_SERVICE_ADDR") + ?? throw new ArgumentNullException("KAFKA_SERVICE_ADDR"); + + _consumer = BuildConsumer(servers); + _consumer.Subscribe(TopicName); + + _logger.LogInformation($"Connecting to Kafka: {servers}"); + } + + public void StartListening() + { + _isListening = true; + + try + { + while (_isListening) + { + try + { + var consumeResult = _consumer.Consume(); + if (consumeResult.IsPartitionEOF) + { + continue; + } + + ProcessMessage(consumeResult.Message); + } + catch (ConsumeException e) + { + _logger.LogError(e, "Consume error: {0}", e.Error.Reason); + } + } + } + catch (OperationCanceledException) + { + _logger.LogInformation("Closing consumer"); + + _consumer.Close(); + } + } + + private void ProcessMessage(Message message) + { + Log.LogOrderReceivedMessage(_logger, message.Value); + } + + private IConsumer BuildConsumer(string servers) + { + var conf = new ConsumerConfig + { + GroupId = $"accountingservice", + BootstrapServers = servers, + // https://github.com/confluentinc/confluent-kafka-dotnet/tree/07de95ed647af80a0db39ce6a8891a630423b952#basic-consumer-example + AutoOffsetReset = AutoOffsetReset.Earliest, + CancellationDelayMaxMs = 10_000, + EnableAutoCommit = true + }; + + return new ConsumerBuilder(conf) + .SetValueDeserializer(new ProtobufDeserializer().AsSyncOverAsync()) + .Build(); + } + + public void Dispose() + { + _isListening = false; + _consumer?.Dispose(); + } +} diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index 8a1ab6556b..e12eb3b7ef 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -1,32 +1,32 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - - -FROM golang:1.22-alpine AS builder - -WORKDIR /usr/src/app - -RUN apk update \ - && apk add --no-cache make protobuf-dev - -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,source=./src/accountingservice/go.sum,target=go.sum \ - --mount=type=bind,source=./src/accountingservice/go.mod,target=go.mod \ - --mount=type=bind,source=./src/accountingservice/tools.go,target=tools.go \ - go mod download \ - && go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly - -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=bind,rw,source=./src/accountingservice,target=. \ - --mount=type=bind,rw,source=./pb,target=./pb \ - protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \ - && go build -ldflags "-s -w" -o /go/bin/accountingservice/ ./ - -FROM alpine - -WORKDIR /usr/src/app/ - -COPY --from=builder /go/bin/accountingservice/ ./ - -ENTRYPOINT [ "./accountingservice" ] +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["AccountingService/AccountingService.csproj", "AccountingService/"] +RUN dotnet restore "./AccountingService/AccountingService.csproj" +COPY . . +WORKDIR "/src/AccountingService" +RUN dotnet build "./AccountingService.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./AccountingService.csproj" --use-current-runtime -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . + +USER root +RUN mkdir -p "/var/log/opentelemetry/dotnet" +RUN chown app "/var/log/opentelemetry/dotnet" +USER app + +ENV OTEL_TRACES_EXPORTER=otlp +ENV OTEL_METRICS_EXPORTER=none +ENV OTEL_LOGS_EXPORTER=otlp +ENV OTEL_LOG_LEVEL=debug + +ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"] \ No newline at end of file diff --git a/src/accountingservice/Helpers.cs b/src/accountingservice/Helpers.cs new file mode 100644 index 0000000000..18adc8e67e --- /dev/null +++ b/src/accountingservice/Helpers.cs @@ -0,0 +1,31 @@ +using System.Collections; + +namespace AccountingService +{ + internal static class Helpers + { + private static List RelevantPrefixes = ["DOTNET_", "CORECLR_", "OTEL_", "KAFKA_"]; + + public static IEnumerable FilterRelevant(this IDictionary envs) + { + foreach (DictionaryEntry env in envs) + { + foreach (var prefix in RelevantPrefixes) + { + if (env.Key.ToString()?.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase) ?? false) + { + yield return env; + } + } + } + } + + public static void OutputInOrder(this IEnumerable envs) + { + foreach (var env in envs.OrderBy(x => x.Key)) + { + Console.WriteLine(env); + } + } + } +} diff --git a/src/accountingservice/Log.cs b/src/accountingservice/Log.cs new file mode 100644 index 0000000000..923b5b730a --- /dev/null +++ b/src/accountingservice/Log.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.Logging; +using Oteldemo; + +namespace AccountingService +{ + internal static partial class Log + { + [LoggerMessage( + Level = LogLevel.Information, + Message = "Order details: {@OrderResult}.")] + public static partial void LogOrderReceivedMessage(ILogger logger, OrderResult orderResult); + } +} diff --git a/src/accountingservice/Program.cs b/src/accountingservice/Program.cs new file mode 100644 index 0000000000..ce7e34db1b --- /dev/null +++ b/src/accountingservice/Program.cs @@ -0,0 +1,21 @@ +using AccountingService; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +Console.WriteLine("Accounting service started"); + +Environment.GetEnvironmentVariables() + .FilterRelevant() + .OutputInOrder(); + +var host = Host.CreateDefaultBuilder(args) + .ConfigureServices(services => + { + services.AddSingleton(); + }) + .Build(); + +var consumer = host.Services.GetRequiredService(); +consumer.StartListening(); + +host.Run(); \ No newline at end of file diff --git a/src/accountingservice/README.md b/src/accountingservice/README.md index 6cd79fb6ba..c7138676e6 100644 --- a/src/accountingservice/README.md +++ b/src/accountingservice/README.md @@ -7,7 +7,7 @@ This service consumes new orders from a Kafka topic. To build the service binary, run: ```sh -go build -o /go/bin/accountingservice/ +dotnet build ``` ## Docker Build @@ -18,22 +18,10 @@ From the root directory, run: docker compose build accountingservice ``` -## Regenerate protos - -> [!NOTE] -> [`protoc`](https://grpc.io/docs/protoc-installation/) is required. - -To regenerate gRPC code run: - -```sh -go generate -``` - ## Bump dependencies -To bump all dependencies run: +To bump all dependencies run in Package manager: ```sh -go get -u -t ./... -go mod tidy +Update-Package -ProjectName AccountingService ``` diff --git a/src/accountingservice/kafka/consumer.go b/src/accountingservice/kafka/consumer.go deleted file mode 100644 index 2b1ab2b490..0000000000 --- a/src/accountingservice/kafka/consumer.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -package kafka - -import ( - "context" - pb "github.com/open-telemetry/opentelemetry-demo/src/accountingservice/genproto/oteldemo" - - "github.com/IBM/sarama" - "github.com/sirupsen/logrus" - "google.golang.org/protobuf/proto" -) - -var ( - Topic = "orders" - ProtocolVersion = sarama.V3_0_0_0 - GroupID = "accountingservice" -) - -func StartConsumerGroup(ctx context.Context, brokers []string, log *logrus.Logger) (sarama.ConsumerGroup, error) { - saramaConfig := sarama.NewConfig() - saramaConfig.Version = ProtocolVersion - // So we can know the partition and offset of messages. - saramaConfig.Producer.Return.Successes = true - saramaConfig.Consumer.Interceptors = []sarama.ConsumerInterceptor{NewOTelInterceptor(GroupID)} - - consumerGroup, err := sarama.NewConsumerGroup(brokers, GroupID, saramaConfig) - if err != nil { - return nil, err - } - - handler := groupHandler{ - log: log, - } - - err = consumerGroup.Consume(ctx, []string{Topic}, &handler) - if err != nil { - return nil, err - } - - return consumerGroup, nil -} - -type groupHandler struct { - log *logrus.Logger -} - -func (g *groupHandler) Setup(_ sarama.ConsumerGroupSession) error { - return nil -} - -func (g *groupHandler) Cleanup(_ sarama.ConsumerGroupSession) error { - return nil -} - -func (g *groupHandler) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error { - for { - select { - case message := <-claim.Messages(): - orderResult := pb.OrderResult{} - err := proto.Unmarshal(message.Value, &orderResult) - if err != nil { - return err - } - - g.log.WithFields(logrus.Fields{ - "orderId": orderResult.OrderId, - "messageTimestamp": message.Timestamp, - "messageTopic": message.Topic, - }).Info("Message claimed") - session.MarkMessage(message, "") - - case <-session.Context().Done(): - return nil - } - } -} diff --git a/src/accountingservice/kafka/trace_interceptor.go b/src/accountingservice/kafka/trace_interceptor.go deleted file mode 100644 index 91d26539a0..0000000000 --- a/src/accountingservice/kafka/trace_interceptor.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -package kafka - -import ( - "context" - "fmt" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/propagation" - semconv "go.opentelemetry.io/otel/semconv/v1.24.0" - "go.opentelemetry.io/otel/trace" - - "github.com/IBM/sarama" -) - -type OTelInterceptor struct { - tracer trace.Tracer - fixedAttrs []attribute.KeyValue -} - -// NewOTelInterceptor processes span for intercepted messages and add some -// headers with the span data. -func NewOTelInterceptor(groupID string) *OTelInterceptor { - oi := OTelInterceptor{} - oi.tracer = otel.Tracer("accountingservice") - - oi.fixedAttrs = []attribute.KeyValue{ - semconv.MessagingSystemKafka, - semconv.MessagingOperationReceive, - semconv.MessagingKafkaConsumerGroup(groupID), - semconv.NetworkTransportTCP, - } - return &oi -} - -func (oi *OTelInterceptor) OnConsume(msg *sarama.ConsumerMessage) { - headers := propagation.MapCarrier{} - - for _, recordHeader := range msg.Headers { - headers[string(recordHeader.Key)] = string(recordHeader.Value) - } - - propagator := otel.GetTextMapPropagator() - ctx := propagator.Extract(context.Background(), headers) - - _, span := oi.tracer.Start( - ctx, - fmt.Sprintf("%s receive", msg.Topic), - trace.WithSpanKind(trace.SpanKindConsumer), - trace.WithAttributes(oi.fixedAttrs...), - trace.WithAttributes( - semconv.MessagingDestinationName(msg.Topic), - semconv.MessagingKafkaMessageOffset(int(msg.Offset)), - semconv.MessagingMessageBodySize(len(msg.Value)), - semconv.MessagingOperationReceive, - semconv.MessagingKafkaDestinationPartition(int(msg.Partition)), - ), - ) - defer span.End() -} diff --git a/src/accountingservice/main.go b/src/accountingservice/main.go deleted file mode 100644 index e2eb7a3dd0..0000000000 --- a/src/accountingservice/main.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 -package main - -//go:generate go install google.golang.org/protobuf/cmd/protoc-gen-go -//go:generate go install google.golang.org/grpc/cmd/protoc-gen-go-grpc -//go:generate protoc --go_out=./ --go-grpc_out=./ --proto_path=../../pb ../../pb/demo.proto - -import ( - "context" - "fmt" - "os" - "os/signal" - "strings" - "sync" - "syscall" - "time" - - "github.com/IBM/sarama" - "github.com/sirupsen/logrus" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" - "go.opentelemetry.io/otel/propagation" - sdkresource "go.opentelemetry.io/otel/sdk/resource" - sdktrace "go.opentelemetry.io/otel/sdk/trace" - - "github.com/open-telemetry/opentelemetry-demo/src/accountingservice/kafka" -) - -var log *logrus.Logger -var resource *sdkresource.Resource -var initResourcesOnce sync.Once - -func init() { - log = logrus.New() - log.Level = logrus.DebugLevel - log.Formatter = &logrus.JSONFormatter{ - FieldMap: logrus.FieldMap{ - logrus.FieldKeyTime: "timestamp", - logrus.FieldKeyLevel: "severity", - logrus.FieldKeyMsg: "message", - }, - TimestampFormat: time.RFC3339Nano, - } - log.Out = os.Stdout -} - -func initResource() *sdkresource.Resource { - initResourcesOnce.Do(func() { - extraResources, _ := sdkresource.New( - context.Background(), - sdkresource.WithOS(), - sdkresource.WithProcess(), - sdkresource.WithContainer(), - sdkresource.WithHost(), - ) - resource, _ = sdkresource.Merge( - sdkresource.Default(), - extraResources, - ) - }) - return resource -} - -func initTracerProvider() (*sdktrace.TracerProvider, error) { - ctx := context.Background() - - exporter, err := otlptracegrpc.New(ctx) - if err != nil { - return nil, err - } - tp := sdktrace.NewTracerProvider( - sdktrace.WithBatcher(exporter), - sdktrace.WithResource(initResource()), - ) - otel.SetTracerProvider(tp) - otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) - return tp, nil -} - -func main() { - tp, err := initTracerProvider() - if err != nil { - log.Fatal(err) - } - defer func() { - if err := tp.Shutdown(context.Background()); err != nil { - log.Printf("Error shutting down tracer provider: %v", err) - } - log.Println("Shutdown trace provider") - }() - - var brokers string - mustMapEnv(&brokers, "KAFKA_SERVICE_ADDR") - - brokerList := strings.Split(brokers, ",") - log.Printf("Kafka brokers: %s", strings.Join(brokerList, ", ")) - - ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGKILL) - defer cancel() - var consumerGroup sarama.ConsumerGroup - if consumerGroup, err = kafka.StartConsumerGroup(ctx, brokerList, log); err != nil { - log.Fatal(err) - } - defer func() { - if err := consumerGroup.Close(); err != nil { - log.Printf("Error closing consumer group: %v", err) - } - log.Println("Closed consumer group") - }() - - <-ctx.Done() - - log.Println("Accounting service exited") -} - -func mustMapEnv(target *string, envKey string) { - v := os.Getenv(envKey) - if v == "" { - panic(fmt.Sprintf("environment variable %q not set", envKey)) - } - *target = v -} diff --git a/src/accountingservice/tools.go b/src/accountingservice/tools.go deleted file mode 100644 index 3557ee5358..0000000000 --- a/src/accountingservice/tools.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -//go:build tools -// +build tools - -package tools - -// This file follows the recommendation at -// https://go.dev/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module -// on how to pin tooling dependencies to a go.mod file. -// This ensures that all systems use the same version of tools in addition to regular dependencies. - -import ( - _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" - _ "google.golang.org/protobuf/cmd/protoc-gen-go" -) From b89e534af81cd2879586b9840167b820c37e1ec5 Mon Sep 17 00:00:00 2001 From: RassK Date: Fri, 19 Apr 2024 14:54:38 +0300 Subject: [PATCH 02/15] fix path --- src/accountingservice/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index e12eb3b7ef..9d1d9768b9 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["AccountingService/AccountingService.csproj", "AccountingService/"] +COPY ["/src/AccountingService/AccountingService.csproj", "AccountingService/"] RUN dotnet restore "./AccountingService/AccountingService.csproj" COPY . . WORKDIR "/src/AccountingService" From 7576862c1bba5897b41817ee9c86e562134306bd Mon Sep 17 00:00:00 2001 From: RassK Date: Fri, 19 Apr 2024 14:56:10 +0300 Subject: [PATCH 03/15] fix folder name --- src/accountingservice/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index 9d1d9768b9..ae2a742321 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["/src/AccountingService/AccountingService.csproj", "AccountingService/"] +COPY ["/src/accountingservice/AccountingService.csproj", "AccountingService/"] RUN dotnet restore "./AccountingService/AccountingService.csproj" COPY . . WORKDIR "/src/AccountingService" From f68fd76c12908663093e147225b2ae91f7f6a26d Mon Sep 17 00:00:00 2001 From: RassK Date: Fri, 19 Apr 2024 15:57:33 +0300 Subject: [PATCH 04/15] dockerfile and other fixes --- src/accountingservice/AccountingService.csproj | 2 +- src/accountingservice/Dockerfile | 7 ++++--- src/accountingservice/Log.cs | 2 +- src/accountingservice/Program.cs | 2 +- src/accountingservice/README.md | 3 ++- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/accountingservice/AccountingService.csproj b/src/accountingservice/AccountingService.csproj index c1f2bae683..d1d63b03af 100644 --- a/src/accountingservice/AccountingService.csproj +++ b/src/accountingservice/AccountingService.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index ae2a742321..e81b8ba56e 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -5,10 +5,11 @@ WORKDIR /app FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["/src/accountingservice/AccountingService.csproj", "AccountingService/"] +COPY ["/src/accountingservice/", "AccountingService/"] +COPY ["/pb/demo.proto", "AccountingService/proto/"] RUN dotnet restore "./AccountingService/AccountingService.csproj" -COPY . . WORKDIR "/src/AccountingService" + RUN dotnet build "./AccountingService.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish @@ -25,7 +26,7 @@ RUN chown app "/var/log/opentelemetry/dotnet" USER app ENV OTEL_TRACES_EXPORTER=otlp -ENV OTEL_METRICS_EXPORTER=none +ENV OTEL_METRICS_EXPORTER=otlp ENV OTEL_LOGS_EXPORTER=otlp ENV OTEL_LOG_LEVEL=debug diff --git a/src/accountingservice/Log.cs b/src/accountingservice/Log.cs index 923b5b730a..a1d75881f1 100644 --- a/src/accountingservice/Log.cs +++ b/src/accountingservice/Log.cs @@ -6,7 +6,7 @@ namespace AccountingService internal static partial class Log { [LoggerMessage( - Level = LogLevel.Information, + Level = LogLevel.Information, Message = "Order details: {@OrderResult}.")] public static partial void LogOrderReceivedMessage(ILogger logger, OrderResult orderResult); } diff --git a/src/accountingservice/Program.cs b/src/accountingservice/Program.cs index ce7e34db1b..4622456d79 100644 --- a/src/accountingservice/Program.cs +++ b/src/accountingservice/Program.cs @@ -18,4 +18,4 @@ var consumer = host.Services.GetRequiredService(); consumer.StartListening(); -host.Run(); \ No newline at end of file +host.Run(); diff --git a/src/accountingservice/README.md b/src/accountingservice/README.md index c7138676e6..9c0f57ef13 100644 --- a/src/accountingservice/README.md +++ b/src/accountingservice/README.md @@ -7,7 +7,8 @@ This service consumes new orders from a Kafka topic. To build the service binary, run: ```sh -dotnet build +cp pb/demo.proto src/accoutingservice/proto/demo.proto # root context +dotnet build # accounting service context ``` ## Docker Build From 3d175eb4ecd7f6d0c5093af6e981c6da0e0a17e5 Mon Sep 17 00:00:00 2001 From: RassK Date: Fri, 19 Apr 2024 16:04:22 +0300 Subject: [PATCH 05/15] add copyright --- src/accountingservice/Consumer.cs | 5 ++++- src/accountingservice/Dockerfile | 3 +++ src/accountingservice/Helpers.cs | 5 ++++- src/accountingservice/Log.cs | 5 ++++- src/accountingservice/Program.cs | 5 ++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/accountingservice/Consumer.cs b/src/accountingservice/Consumer.cs index 5e6182e8aa..bc74e948cf 100644 --- a/src/accountingservice/Consumer.cs +++ b/src/accountingservice/Consumer.cs @@ -1,4 +1,7 @@ -using Confluent.Kafka; +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using Confluent.Kafka; using Confluent.Kafka.SyncOverAsync; using Confluent.SchemaRegistry.Serdes; using Microsoft.Extensions.Logging; diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index e81b8ba56e..79c0dc59a2 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base USER app WORKDIR /app diff --git a/src/accountingservice/Helpers.cs b/src/accountingservice/Helpers.cs index 18adc8e67e..bb41f8c46f 100644 --- a/src/accountingservice/Helpers.cs +++ b/src/accountingservice/Helpers.cs @@ -1,4 +1,7 @@ -using System.Collections; +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Collections; namespace AccountingService { diff --git a/src/accountingservice/Log.cs b/src/accountingservice/Log.cs index a1d75881f1..f50784aa9d 100644 --- a/src/accountingservice/Log.cs +++ b/src/accountingservice/Log.cs @@ -1,4 +1,7 @@ -using Microsoft.Extensions.Logging; +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using Microsoft.Extensions.Logging; using Oteldemo; namespace AccountingService diff --git a/src/accountingservice/Program.cs b/src/accountingservice/Program.cs index 4622456d79..860d45c2fa 100644 --- a/src/accountingservice/Program.cs +++ b/src/accountingservice/Program.cs @@ -1,4 +1,7 @@ -using AccountingService; +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using AccountingService; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; From 52de9ba98c9a896f387b32cd123cb8c61bcc2a60 Mon Sep 17 00:00:00 2001 From: RassK Date: Fri, 19 Apr 2024 16:10:09 +0300 Subject: [PATCH 06/15] fix encoding and cleanup --- .../AccountingService.csproj | 2 +- src/accountingservice/AccountingService.sln | 2 +- src/accountingservice/Consumer.cs | 2 +- src/accountingservice/Dockerfile | 2 +- src/accountingservice/Helpers.cs | 2 +- src/accountingservice/Log.cs | 2 +- src/accountingservice/Program.cs | 2 +- src/accountingservice/go.mod | 47 ------ src/accountingservice/go.sum | 142 ------------------ 9 files changed, 7 insertions(+), 196 deletions(-) delete mode 100644 src/accountingservice/go.mod delete mode 100644 src/accountingservice/go.sum diff --git a/src/accountingservice/AccountingService.csproj b/src/accountingservice/AccountingService.csproj index d1d63b03af..a410796831 100644 --- a/src/accountingservice/AccountingService.csproj +++ b/src/accountingservice/AccountingService.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/accountingservice/AccountingService.sln b/src/accountingservice/AccountingService.sln index e7ee43df26..ee5a41ca9f 100644 --- a/src/accountingservice/AccountingService.sln +++ b/src/accountingservice/AccountingService.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34701.34 diff --git a/src/accountingservice/Consumer.cs b/src/accountingservice/Consumer.cs index bc74e948cf..1d171b877a 100644 --- a/src/accountingservice/Consumer.cs +++ b/src/accountingservice/Consumer.cs @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 using Confluent.Kafka; diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index 79c0dc59a2..0553b37bb7 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -33,4 +33,4 @@ ENV OTEL_METRICS_EXPORTER=otlp ENV OTEL_LOGS_EXPORTER=otlp ENV OTEL_LOG_LEVEL=debug -ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"] \ No newline at end of file +ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"] diff --git a/src/accountingservice/Helpers.cs b/src/accountingservice/Helpers.cs index bb41f8c46f..c757378338 100644 --- a/src/accountingservice/Helpers.cs +++ b/src/accountingservice/Helpers.cs @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 using System.Collections; diff --git a/src/accountingservice/Log.cs b/src/accountingservice/Log.cs index f50784aa9d..fef49c21fc 100644 --- a/src/accountingservice/Log.cs +++ b/src/accountingservice/Log.cs @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 using Microsoft.Extensions.Logging; diff --git a/src/accountingservice/Program.cs b/src/accountingservice/Program.cs index 860d45c2fa..1f122a7ebc 100644 --- a/src/accountingservice/Program.cs +++ b/src/accountingservice/Program.cs @@ -1,4 +1,4 @@ -// Copyright The OpenTelemetry Authors +// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 using AccountingService; diff --git a/src/accountingservice/go.mod b/src/accountingservice/go.mod deleted file mode 100644 index 5b9df001e4..0000000000 --- a/src/accountingservice/go.mod +++ /dev/null @@ -1,47 +0,0 @@ -module github.com/open-telemetry/opentelemetry-demo/src/accountingservice - -go 1.22 - -require ( - github.com/IBM/sarama v1.43.1 - github.com/sirupsen/logrus v1.9.3 - go.opentelemetry.io/otel v1.25.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.25.0 - go.opentelemetry.io/otel/sdk v1.25.0 - go.opentelemetry.io/otel/trace v1.25.0 - google.golang.org/grpc v1.63.2 - google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 - google.golang.org/protobuf v1.33.0 -) - -require ( - github.com/cenkalti/backoff/v4 v4.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/eapache/go-resiliency v1.6.0 // indirect - github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect - github.com/eapache/queue v1.1.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect - github.com/go-logr/stdr v1.2.2 // indirect - github.com/golang/snappy v0.0.4 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/jcmturner/aescts/v2 v2.0.0 // indirect - github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect - github.com/jcmturner/gofork v1.7.6 // indirect - github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect - github.com/jcmturner/rpc/v2 v2.0.3 // indirect - github.com/klauspost/compress v1.17.7 // indirect - github.com/pierrec/lz4/v4 v4.1.21 // indirect - github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.25.0 // indirect - go.opentelemetry.io/otel/metric v1.25.0 // indirect - go.opentelemetry.io/proto/otlp v1.1.0 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect -) diff --git a/src/accountingservice/go.sum b/src/accountingservice/go.sum deleted file mode 100644 index f68c4d2820..0000000000 --- a/src/accountingservice/go.sum +++ /dev/null @@ -1,142 +0,0 @@ -github.com/IBM/sarama v1.43.1 h1:Z5uz65Px7f4DhI/jQqEm/tV9t8aU+JUdTyW/K/fCXpA= -github.com/IBM/sarama v1.43.1/go.mod h1:GG5q1RURtDNPz8xxJs3mgX6Ytak8Z9eLhAkJPObe2xE= -github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= -github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/eapache/go-resiliency v1.6.0 h1:CqGDTLtpwuWKn6Nj3uNUdflaq+/kIPsg0gfNzHton30= -github.com/eapache/go-resiliency v1.6.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= -github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= -github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= -github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= -github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= -github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= -github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= -github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= -github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= -github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg= -github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= -github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= -github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= -github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8= -github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= -github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= -github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= -github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= -github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k= -go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.25.0 h1:dT33yIHtmsqpixFsSQPwNeY5drM9wTcoL8h0FWF4oGM= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.25.0/go.mod h1:h95q0LBGh7hlAC08X2DhSeyIG02YQ0UyioTCVAqRPmc= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.25.0 h1:vOL89uRfOCCNIjkisd0r7SEdJF3ZJFyCNY34fdZs8eU= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.25.0/go.mod h1:8GlBGcDk8KKi7n+2S4BT/CPZQYH3erLu0/k64r1MYgo= -go.opentelemetry.io/otel/metric v1.25.0 h1:LUKbS7ArpFL/I2jJHdJcqMGxkRdxpPHE0VU/D4NuEwA= -go.opentelemetry.io/otel/metric v1.25.0/go.mod h1:rkDLUSd2lC5lq2dFNrX9LGAbINP5B7WBkC78RXCpH5s= -go.opentelemetry.io/otel/sdk v1.25.0 h1:PDryEJPC8YJZQSyLY5eqLeafHtG+X7FWnf3aXMtxbqo= -go.opentelemetry.io/otel/sdk v1.25.0/go.mod h1:oFgzCM2zdsxKzz6zwpTZYLLQsFwc+K0daArPdIhuxkw= -go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM= -go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I= -go.opentelemetry.io/proto/otlp v1.1.0 h1:2Di21piLrCqJ3U3eXGCTPHE9R8Nh+0uglSnOyxikMeI= -go.opentelemetry.io/proto/otlp v1.1.0/go.mod h1:GpBHCBWiqvVLDqmHZsoMM3C5ySeKTC7ej/RNTae6MdY= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= -google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= -google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= -google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 22c33f21935333e7b707aa29d0737b7e2ee6d3b5 Mon Sep 17 00:00:00 2001 From: RassK Date: Mon, 22 Apr 2024 11:46:18 +0300 Subject: [PATCH 07/15] Cleanup dockerfile --- src/accountingservice/Dockerfile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index 0553b37bb7..f2410184cc 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -28,9 +28,4 @@ RUN mkdir -p "/var/log/opentelemetry/dotnet" RUN chown app "/var/log/opentelemetry/dotnet" USER app -ENV OTEL_TRACES_EXPORTER=otlp -ENV OTEL_METRICS_EXPORTER=otlp -ENV OTEL_LOGS_EXPORTER=otlp -ENV OTEL_LOG_LEVEL=debug - ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"] From 89892d29218f612866812f14126633610db27e14 Mon Sep 17 00:00:00 2001 From: RassK Date: Tue, 30 Apr 2024 12:25:53 +0300 Subject: [PATCH 08/15] Update OTel Auto --- src/accountingservice/AccountingService.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accountingservice/AccountingService.csproj b/src/accountingservice/AccountingService.csproj index a410796831..62401ccd98 100644 --- a/src/accountingservice/AccountingService.csproj +++ b/src/accountingservice/AccountingService.csproj @@ -18,7 +18,7 @@ - + From 7523884ea18ee4b59552e17cbd3541bd4f46a1ed Mon Sep 17 00:00:00 2001 From: RassK Date: Tue, 30 Apr 2024 15:45:18 +0300 Subject: [PATCH 09/15] fix kafka processing issues and otel export --- docker-compose.yml | 4 +-- .../AccountingService.csproj | 5 +++- src/accountingservice/Consumer.cs | 25 ++++++++++++------- src/accountingservice/Log.cs | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 220ce155d4..a89df52d02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,11 +30,11 @@ services: deploy: resources: limits: - memory: 20M + memory: 50M restart: unless-stopped environment: - KAFKA_SERVICE_ADDR - - OTEL_EXPORTER_OTLP_ENDPOINT + - OTEL_EXPORTER_OTLP_ENDPOINT=http://${OTEL_COLLECTOR_HOST}:${OTEL_COLLECTOR_PORT_HTTP} - OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE - OTEL_RESOURCE_ATTRIBUTES - OTEL_SERVICE_NAME=accountingservice diff --git a/src/accountingservice/AccountingService.csproj b/src/accountingservice/AccountingService.csproj index 62401ccd98..964dc4e987 100644 --- a/src/accountingservice/AccountingService.csproj +++ b/src/accountingservice/AccountingService.csproj @@ -10,7 +10,6 @@ - all @@ -26,4 +25,8 @@ + + + + diff --git a/src/accountingservice/Consumer.cs b/src/accountingservice/Consumer.cs index 1d171b877a..e832e91fd3 100644 --- a/src/accountingservice/Consumer.cs +++ b/src/accountingservice/Consumer.cs @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 using Confluent.Kafka; -using Confluent.Kafka.SyncOverAsync; -using Confluent.SchemaRegistry.Serdes; using Microsoft.Extensions.Logging; using Oteldemo; @@ -14,7 +12,7 @@ internal class Consumer : IDisposable private const string TopicName = "orders"; private ILogger _logger; - private IConsumer _consumer; + private IConsumer _consumer; private bool _isListening; public Consumer(ILogger logger) @@ -62,12 +60,21 @@ public void StartListening() } } - private void ProcessMessage(Message message) + private void ProcessMessage(Message message) { - Log.LogOrderReceivedMessage(_logger, message.Value); + try + { + var order = OrderResult.Parser.ParseFrom(message.Value); + + Log.OrderReceivedMessage(_logger, order); + } + catch (Exception ex) + { + _logger.LogError(ex, "Order parsing failed:"); + } } - private IConsumer BuildConsumer(string servers) + private IConsumer BuildConsumer(string servers) { var conf = new ConsumerConfig { @@ -76,11 +83,11 @@ private IConsumer BuildConsumer(string servers) // https://github.com/confluentinc/confluent-kafka-dotnet/tree/07de95ed647af80a0db39ce6a8891a630423b952#basic-consumer-example AutoOffsetReset = AutoOffsetReset.Earliest, CancellationDelayMaxMs = 10_000, - EnableAutoCommit = true + EnableAutoCommit = true, + EnablePartitionEof = true, }; - return new ConsumerBuilder(conf) - .SetValueDeserializer(new ProtobufDeserializer().AsSyncOverAsync()) + return new ConsumerBuilder(conf) .Build(); } diff --git a/src/accountingservice/Log.cs b/src/accountingservice/Log.cs index fef49c21fc..73bfb3f557 100644 --- a/src/accountingservice/Log.cs +++ b/src/accountingservice/Log.cs @@ -11,6 +11,6 @@ internal static partial class Log [LoggerMessage( Level = LogLevel.Information, Message = "Order details: {@OrderResult}.")] - public static partial void LogOrderReceivedMessage(ILogger logger, OrderResult orderResult); + public static partial void OrderReceivedMessage(ILogger logger, OrderResult orderResult); } } From a35283c96496dcc24d609b8f560771651f7ac648 Mon Sep 17 00:00:00 2001 From: RassK Date: Tue, 30 Apr 2024 16:30:59 +0300 Subject: [PATCH 10/15] remove eof --- src/accountingservice/Consumer.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/accountingservice/Consumer.cs b/src/accountingservice/Consumer.cs index e832e91fd3..33fafc72f3 100644 --- a/src/accountingservice/Consumer.cs +++ b/src/accountingservice/Consumer.cs @@ -39,10 +39,6 @@ public void StartListening() try { var consumeResult = _consumer.Consume(); - if (consumeResult.IsPartitionEOF) - { - continue; - } ProcessMessage(consumeResult.Message); } @@ -83,8 +79,7 @@ private IConsumer BuildConsumer(string servers) // https://github.com/confluentinc/confluent-kafka-dotnet/tree/07de95ed647af80a0db39ce6a8891a630423b952#basic-consumer-example AutoOffsetReset = AutoOffsetReset.Earliest, CancellationDelayMaxMs = 10_000, - EnableAutoCommit = true, - EnablePartitionEof = true, + EnableAutoCommit = true }; return new ConsumerBuilder(conf) From 083cdc96fb1e23a42bccd6c4ef1a20d2cedb2cd8 Mon Sep 17 00:00:00 2001 From: RassK Date: Mon, 6 May 2024 11:33:50 +0300 Subject: [PATCH 11/15] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f37500f6be..5463e4994f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ the release. ([#1551](https://github.com/open-telemetry/opentelemetry-demo/pull/1551)) * [flagd] update to 0.10.1 and set 50M memory limit ([#1554](https://github.com/open-telemetry/opentelemetry-demo/pull/1554)) +* [accountingservice] convert from Go service to .NET service, uses + OpenTelemetry .NET Automatic Instrumentation. + ([#1538](https://github.com/open-telemetry/opentelemetry-demo/pull/1538)) ## 1.9.0 From 6ada38449b3714839b2775373c437764a513bb3f Mon Sep 17 00:00:00 2001 From: RassK Date: Wed, 15 May 2024 12:07:44 +0300 Subject: [PATCH 12/15] Use default CancellationDelayMaxMs --- src/accountingservice/Consumer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/accountingservice/Consumer.cs b/src/accountingservice/Consumer.cs index 33fafc72f3..70f9357fea 100644 --- a/src/accountingservice/Consumer.cs +++ b/src/accountingservice/Consumer.cs @@ -78,7 +78,6 @@ private IConsumer BuildConsumer(string servers) BootstrapServers = servers, // https://github.com/confluentinc/confluent-kafka-dotnet/tree/07de95ed647af80a0db39ce6a8891a630423b952#basic-consumer-example AutoOffsetReset = AutoOffsetReset.Earliest, - CancellationDelayMaxMs = 10_000, EnableAutoCommit = true }; From 43867ae351a532cae1f4de851ed973b22a829a67 Mon Sep 17 00:00:00 2001 From: RassK Date: Wed, 19 Jun 2024 15:00:10 +0300 Subject: [PATCH 13/15] update packages --- src/accountingservice/AccountingService.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/accountingservice/AccountingService.csproj b/src/accountingservice/AccountingService.csproj index 964dc4e987..3a26192587 100644 --- a/src/accountingservice/AccountingService.csproj +++ b/src/accountingservice/AccountingService.csproj @@ -9,15 +9,15 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + From d02a6c1869c4d998990443557e0f818403b16a50 Mon Sep 17 00:00:00 2001 From: RassK Date: Wed, 19 Jun 2024 15:42:15 +0300 Subject: [PATCH 14/15] fix merge failure --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b22602fad..257373c3cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ the release. * [cartservice] bump .NET package to 1.9.0 release ([#1610](https://github.com/open-telemetry/opentelemetry-demo/pull/1610)) +* [accountingservice] convert from Go service to .NET service, uses + OpenTelemetry .NET Automatic Instrumentation. + ([#1538](https://github.com/open-telemetry/opentelemetry-demo/pull/1538)) ## 1.10.0 @@ -55,9 +58,6 @@ the release. ([#1594](https://github.com/open-telemetry/opentelemetry-demo/pull/1594)) * [checkout] increase Kafka resiliency and observability ([#1590](https://github.com/open-telemetry/opentelemetry-demo/pull/1590)) -* [accountingservice] convert from Go service to .NET service, uses - OpenTelemetry .NET Automatic Instrumentation. - ([#1538](https://github.com/open-telemetry/opentelemetry-demo/pull/1538)) ## 1.9.0 From fb460d4facda97d71bec90f51b0bbb063f4e92e8 Mon Sep 17 00:00:00 2001 From: Juliano Costa Date: Thu, 20 Jun 2024 10:08:46 +0200 Subject: [PATCH 15/15] Fix tracetest 'accountingservice' is not part of the trace anymore --- test/tracetesting/frontend-service/06-checking-out-cart.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/tracetesting/frontend-service/06-checking-out-cart.yaml b/test/tracetesting/frontend-service/06-checking-out-cart.yaml index b1372d2597..d8d4748e63 100644 --- a/test/tracetesting/frontend-service/06-checking-out-cart.yaml +++ b/test/tracetesting/frontend-service/06-checking-out-cart.yaml @@ -62,8 +62,3 @@ spec: selector: span[tracetest.span.type="messaging" name="orders publish" messaging.system="kafka" messaging.destination.name="orders" messaging.operation="publish"] assertions: - attr:messaging.destination.name = "orders" - - name: The order was sent to accountability - # captures the span emitted by Kafka instrumentation for Go - selector: span[tracetest.span.type="messaging" name="orders receive" messaging.system="kafka" messaging.destination.name="orders" messaging.operation="receive"] - assertions: - - attr:name = "orders receive"