-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redis instrumentation with ActivitySource by Eddy & Mike (#800)
* Attempting to get Redis instrumentation up and working using ActivitySource API. * updating tests * renaming and updating tests * Test fixes. * Fixed Redis net461 tests failing on connection. * Redis integration tests and bug fixes. * Adding tests * Put back redis connection options. * Updates for changes in master. * adding comments to testRedis * updating based on comments * updating summary * Switched a couple spots using string keys to constants. * Redis integration tests * Small tweak to the GitHub action to make it more consistent with the others. * Made instrumentation internal. Updated README. * rename MaxFlushInterval to FlushInterval, adding flushInterval to samples * Removed running of non-integration tests from Redis dockerfile. Co-authored-by: Eddy Nakamura <eddynaka@gmail.com> Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
- Loading branch information
1 parent
3214f1c
commit 9298e0e
Showing
27 changed files
with
674 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/bin | ||
**/obj | ||
**/*.yaml | ||
**/*.yml | ||
**/*.md | ||
**/*.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Redis Integration Tests | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build-compose-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run redis docker-compose.integration | ||
run: docker-compose --file=test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/docker-compose.integration.yml --project-directory=. up --exit-code-from=redis_integration_tests --build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...nstrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// <copyright file="RedisProfilerEntryToActivityConverter.cs" company="OpenTelemetry Authors"> | ||
// Copyright 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. | ||
// </copyright> | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Net; | ||
using OpenTelemetry.Trace; | ||
using StackExchange.Redis.Profiling; | ||
|
||
namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation | ||
{ | ||
internal static class RedisProfilerEntryToActivityConverter | ||
{ | ||
public static Activity ProfilerCommandToActivity(Activity parentActivity, IProfiledCommand command) | ||
{ | ||
var name = command.Command; // Example: SET; | ||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
name = StackExchangeRedisCallsInstrumentation.ActivityName; | ||
} | ||
|
||
var activity = StackExchangeRedisCallsInstrumentation.ActivitySource.StartActivity( | ||
name, | ||
ActivityKind.Client, | ||
parentActivity?.Context ?? default, | ||
startTime: command.CommandCreated); | ||
|
||
if (activity == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (activity.IsAllDataRequested == true) | ||
{ | ||
// see https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md | ||
|
||
// Timing example: | ||
// command.CommandCreated; //2019-01-10 22:18:28Z | ||
|
||
// command.CreationToEnqueued; // 00:00:32.4571995 | ||
// command.EnqueuedToSending; // 00:00:00.0352838 | ||
// command.SentToResponse; // 00:00:00.0060586 | ||
// command.ResponseToCompletion; // 00:00:00.0002601 | ||
|
||
// Total: | ||
// command.ElapsedTime; // 00:00:32.4988020 | ||
|
||
activity.AddTag(SpanAttributeConstants.StatusCodeKey, SpanHelper.GetCachedCanonicalCodeString(StatusCanonicalCode.Ok)); | ||
activity.AddTag(SpanAttributeConstants.DatabaseSystemKey, "redis"); | ||
activity.AddTag(StackExchangeRedisCallsInstrumentation.RedisFlagsKeyName, command.Flags.ToString()); | ||
|
||
if (command.Command != null) | ||
{ | ||
// Example: "db.statement": SET; | ||
activity.AddTag(SpanAttributeConstants.DatabaseStatementKey, command.Command); | ||
} | ||
|
||
if (command.EndPoint != null) | ||
{ | ||
if (command.EndPoint is IPEndPoint ipEndPoint) | ||
{ | ||
activity.AddTag(SpanAttributeConstants.NetPeerIp, ipEndPoint.Address.ToString()); | ||
activity.AddTag(SpanAttributeConstants.NetPeerPort, ipEndPoint.Port.ToString()); | ||
} | ||
else if (command.EndPoint is DnsEndPoint dnsEndPoint) | ||
{ | ||
activity.AddTag(SpanAttributeConstants.NetPeerName, dnsEndPoint.Host); | ||
activity.AddTag(SpanAttributeConstants.NetPeerPort, dnsEndPoint.Port.ToString()); | ||
} | ||
else | ||
{ | ||
activity.AddTag(SpanAttributeConstants.PeerServiceKey, command.EndPoint.ToString()); | ||
} | ||
} | ||
|
||
activity.AddTag(StackExchangeRedisCallsInstrumentation.RedisDatabaseIndexKeyName, command.Db.ToString()); | ||
|
||
// TODO: deal with the re-transmission | ||
// command.RetransmissionOf; | ||
// command.RetransmissionReason; | ||
|
||
var enqueued = command.CommandCreated.Add(command.CreationToEnqueued); | ||
var send = enqueued.Add(command.EnqueuedToSending); | ||
var response = send.Add(command.SentToResponse); | ||
|
||
activity.AddEvent(new ActivityEvent("Enqueued", enqueued)); | ||
activity.AddEvent(new ActivityEvent("Sent", send)); | ||
activity.AddEvent(new ActivityEvent("ResponseReceived", response)); | ||
|
||
activity.SetEndTime(command.CommandCreated + command.ElapsedTime); | ||
} | ||
|
||
activity.Stop(); | ||
|
||
return activity; | ||
} | ||
|
||
public static void DrainSession(Activity parentActivity, IEnumerable<IProfiledCommand> sessionCommands) | ||
{ | ||
foreach (var command in sessionCommands) | ||
{ | ||
ProfilerCommandToActivity(parentActivity, command); | ||
} | ||
} | ||
} | ||
} |
90 changes: 0 additions & 90 deletions
90
...ry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToSpanConverter.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.