diff --git a/CHANGELOG.md b/CHANGELOG.md index b5adff956a..bf151b767c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,3 +186,5 @@ significant modifications will be credited to OpenTelemetry Authors. ([#677](https://github.com/open-telemetry/opentelemetry-demo/pull/677)) * Add custom metrics to ads service ([#678](https://github.com/open-telemetry/opentelemetry-demo/pull/678)) +* Rebuild currency service Dockerfile with alpine +([#687](https://github.com/open-telemetry/opentelemetry-demo/pull/687)) diff --git a/docs/services/currencyservice.md b/docs/services/currencyservice.md index 8f54e810e0..091c85f6ed 100644 --- a/docs/services/currencyservice.md +++ b/docs/services/currencyservice.md @@ -46,10 +46,10 @@ function. std::string span_name = "CurrencyService/Convert"; auto span = get_tracer("currencyservice")->StartSpan(span_name, - {{SemanticConventions::RPC_SYSTEM, "grpc"}, - {SemanticConventions::RPC_SERVICE, "CurrencyService"}, - {SemanticConventions::RPC_METHOD, "Convert"}, - {SemanticConventions::RPC_GRPC_STATUS_CODE, 0}}, + {{SemanticConventions::kRpcSystem, "grpc"}, + {SemanticConventions::kRpcService, "CurrencyService"}, + {SemanticConventions::kRpcMethod, "Convert"}, + {SemanticConventions::kRpcGrpcStatusCode, 0}}, options); auto scope = get_tracer("currencyservice")->WithActiveSpan(span); ``` diff --git a/src/currencyservice/CMakeLists.txt b/src/currencyservice/CMakeLists.txt index 6c83b3fa5a..5ab5120c10 100644 --- a/src/currencyservice/CMakeLists.txt +++ b/src/currencyservice/CMakeLists.txt @@ -62,6 +62,6 @@ add_executable(currencyservice src/server.cpp) add_dependencies(currencyservice demo-proto) target_link_libraries( currencyservice demo-proto protobuf::libprotobuf - opentelemetry_trace opentelemetry_common opentelemetry_exporter_otlp_grpc opentelemetry_proto opentelemetry_otlp_recordable opentelemetry_resources gRPC::grpc++) + opentelemetry_trace opentelemetry_common opentelemetry_exporter_otlp_grpc opentelemetry_exporter_otlp_grpc_client opentelemetry_proto opentelemetry_otlp_recordable opentelemetry_resources gRPC::grpc++) install(TARGETS currencyservice DESTINATION bin) diff --git a/src/currencyservice/Dockerfile b/src/currencyservice/Dockerfile index 8504533a24..935f20327c 100644 --- a/src/currencyservice/Dockerfile +++ b/src/currencyservice/Dockerfile @@ -1,59 +1,47 @@ -FROM ubuntu:20.04 -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get -y update -RUN apt-get -y upgrade && apt-get -y dist-upgrade -RUN apt-get install -qq -y --ignore-missing \ - build-essential \ - git \ - make \ - pkg-config \ - protobuf-compiler \ - libprotobuf-dev \ - libcurl4-openssl-dev \ - nlohmann-json3-dev \ - cmake - -# The following arguments would be passed from docker-compose.yml -ARG GRPC_VERSION=1.46.0 -ARG OPENTELEMETRY_VERSION=1.5.0 - -# Install GRPC -RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v${GRPC_VERSION} \ - https://github.com/grpc/grpc \ - && cd grpc \ - && mkdir -p cmake/build \ - && cd cmake/build \ - && cmake \ - -DgRPC_INSTALL=ON \ - -DgRPC_BUILD_TESTS=OFF \ - -DCMAKE_BUILD_TYPE=Release \ - -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ - -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \ - ../.. \ - && make -j$(nproc || sysctl -n hw.ncpu || echo 1) \ - && make install \ - && cd ../../.. \ - && rm -rf grpc - -# Install OpenTelemetry +# Copyright 2023 The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM alpine as builder + +RUN apk update +RUN apk add git cmake make g++ grpc-dev re2-dev protobuf-dev c-ares-dev + +ARG OPENTELEMETRY_CPP_VERSION=1.8.1 + RUN git clone https://github.com/open-telemetry/opentelemetry-cpp \ - && cd opentelemetry-cpp/ \ - && git checkout tags/v${OPENTELEMETRY_VERSION} -b v${OPENTELEMETRY_VERSION} \ - && git submodule update --init --recursive \ - && mkdir build \ - && cd build \ - && cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_OTLP=ON \ - && make -j install && cd ../.. && rm -rf opentelemetry-cpp + && cd opentelemetry-cpp/ \ + && git checkout tags/v${OPENTELEMETRY_CPP_VERSION} -b v${OPENTELEMETRY_CPP_VERSION} \ + && mkdir build \ + && cd build \ + && cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DWITH_OTLP=ON \ + && make -j$(nproc || sysctl -n hw.ncpu || echo 1) install && cd ../.. && rm -rf opentelemetry-cpp COPY . /currencyservice RUN cd /currencyservice \ && mkdir -p build && cd build \ - && cmake .. && make -j install + && cmake .. \ + && make -j$(nproc || sysctl -n hw.ncpu || echo 1) install + +FROM alpine + +WORKDIR /usr/src/app/ + +RUN apk update +RUN apk add grpc-dev re2-dev protobuf-dev c-ares-dev + +COPY --from=builder /usr/local/bin/currencyservice ./ -ENTRYPOINT /usr/local/bin/currencyservice ${CURRENCY_SERVICE_PORT} +EXPOSE ${CURRENCY_SERVICE_PORT} +ENTRYPOINT ./currencyservice ${CURRENCY_SERVICE_PORT} diff --git a/src/currencyservice/src/server.cpp b/src/currencyservice/src/server.cpp index 6e7d8fa854..3eb731bbc4 100644 --- a/src/currencyservice/src/server.cpp +++ b/src/currencyservice/src/server.cpp @@ -116,10 +116,10 @@ class CurrencyService final : public hipstershop::CurrencyService::Service std::string span_name = "CurrencyService/GetSupportedCurrencies"; auto span = get_tracer("currencyservice")->StartSpan(span_name, - {{SemanticConventions::RPC_SYSTEM, "grpc"}, - {SemanticConventions::RPC_SERVICE, "CurrencyService"}, - {SemanticConventions::RPC_METHOD, "GetSupportedCurrencies"}, - {SemanticConventions::RPC_GRPC_STATUS_CODE, 0}}, + {{SemanticConventions::kRpcSystem, "grpc"}, + {SemanticConventions::kRpcService, "CurrencyService"}, + {SemanticConventions::kRpcMethod, "GetSupportedCurrencies"}, + {SemanticConventions::kRpcGrpcStatusCode, 0}}, options); auto scope = get_tracer("currencyservice")->WithActiveSpan(span); @@ -176,10 +176,10 @@ class CurrencyService final : public hipstershop::CurrencyService::Service std::string span_name = "CurrencyService/Convert"; auto span = get_tracer("currencyservice")->StartSpan(span_name, - {{SemanticConventions::RPC_SYSTEM, "grpc"}, - {SemanticConventions::RPC_SERVICE, "CurrencyService"}, - {SemanticConventions::RPC_METHOD, "Convert"}, - {SemanticConventions::RPC_GRPC_STATUS_CODE, 0}}, + {{SemanticConventions::kRpcSystem, "grpc"}, + {SemanticConventions::kRpcService, "CurrencyService"}, + {SemanticConventions::kRpcMethod, "Convert"}, + {SemanticConventions::kRpcGrpcStatusCode, 0}}, options); auto scope = get_tracer("currencyservice")->WithActiveSpan(span);