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

[cartservice] Add manual instrumentation #183

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/cartservice/src/cartservice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PackageReference Include="Grpc.AspNetCore" Version="2.44.0" />
<PackageReference Include="Grpc.AspNetCore.HealthChecks" Version="2.46.0" />
<PackageReference Include="StackExchange.Redis" Version="2.5.43" />
<PackageReference Include="OpenTelemetry" Version="1.2.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.2.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.0.0-rc9.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" Version="1.0.0-rc9.2" />
<PackageReference Include="OpenTelemetry" Version="1.3.0" />
julianocosta89 marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.3.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" Version="1.0.0-rc9.6" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/cartservice/src/services/CartService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics;
using System.Threading.Tasks;
using Grpc.Core;
using cartservice.cartstore;
Expand All @@ -31,17 +32,30 @@ public CartService(ICartStore cartStore)

public async override Task<Empty> AddItem(AddItemRequest request, ServerCallContext context)
{
var activity = Activity.Current;
activity?.SetTag("app.user.id", request.UserId);
activity?.SetTag("app.product.id", request.Item.ProductId);
activity?.SetTag("app.product.quantity", request.Item.Quantity);

await _cartStore.AddItemAsync(request.UserId, request.Item.ProductId, request.Item.Quantity);
return Empty;
}

public override Task<Cart> GetCart(GetCartRequest request, ServerCallContext context)
{
var activity = Activity.Current;
activity?.SetTag("app.user.id", request.UserId);
activity?.AddEvent(new("Fetch cart"));

return _cartStore.GetCartAsync(request.UserId);
}

public async override Task<Empty> EmptyCart(EmptyCartRequest request, ServerCallContext context)
{
var activity = Activity.Current;
activity?.SetTag("app.user.id", request.UserId);
activity?.AddEvent(new("Empty cart"));

await _cartStore.EmptyCartAsync(request.UserId);
return Empty;
}
Expand Down