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

feat(csharp/src/Apache.Arrow.Adbc): add OpenTelemetry compatible tracing support #2559

Open
wants to merge 108 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
27c808c
optel poc - wip #1
birschick-bq Oct 31, 2024
2384ed4
Initial POC for using System.Diagnostics
birschick-bq Nov 7, 2024
3824499
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Nov 7, 2024
351ced6
remove go code
birschick-bq Nov 8, 2024
49f9a72
moved tracing to Connection. Removed from Database/Driver
birschick-bq Nov 8, 2024
4af814a
moved tracing to Connection. Removed from Database/Driver
birschick-bq Nov 8, 2024
9bf476c
add comments about listener lifetimes
birschick-bq Nov 8, 2024
2be0142
remove go code
birschick-bq Nov 8, 2024
4b7997e
remove updates to tests
birschick-bq Nov 8, 2024
1b87b4f
update exception handling
birschick-bq Nov 8, 2024
1264d78
remove go
birschick-bq Nov 8, 2024
753038e
more instrumentation and exception handling
birschick-bq Nov 8, 2024
5749d7a
improved modularization
birschick-bq Nov 8, 2024
b30524f
remove unnecessary updates
birschick-bq Nov 8, 2024
cfbebb3
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Nov 8, 2024
b77490b
updates from review comments to move the tracing code to make easier …
birschick-bq Nov 14, 2024
c4837c4
some clean-up and documentation
birschick-bq Nov 14, 2024
ea7b873
fix trailing space
birschick-bq Nov 14, 2024
a379b23
small update and tracing instrumentation for SparkDatabricksReader
birschick-bq Nov 14, 2024
c018d39
refactored TracingConnection to use common implementation. Added supp…
birschick-bq Nov 14, 2024
d935264
refactored TraceException
birschick-bq Nov 14, 2024
4d874bc
corrected implementation
birschick-bq Nov 14, 2024
40a067d
refactor tracing base
birschick-bq Nov 16, 2024
acc0a1b
remove unnecessary changes
birschick-bq Nov 16, 2024
b2d9c90
remove unnecessary changes
birschick-bq Nov 17, 2024
95658bf
improve listener behaviour. fix missing members
birschick-bq Nov 17, 2024
2625e14
complete comment
birschick-bq Nov 17, 2024
fb74cf1
update version 1.1 connection/statement
birschick-bq Nov 17, 2024
ee11da1
started activity in SparkDatabricksReader
birschick-bq Nov 17, 2024
6f0a759
fixed null handling in TracingBase
birschick-bq Nov 17, 2024
6a6fc3d
add better support for cancellation and retry
birschick-bq Nov 17, 2024
dd78038
refactor to use OpenTelemetry Exporter
birschick-bq Nov 19, 2024
381dce5
clean-up code, documentation, simplify locking
birschick-bq Nov 20, 2024
30ad831
modify the default logging folder
birschick-bq Nov 20, 2024
dc19887
add file exporter tests. Updated driver/database/connection/statement…
birschick-bq Nov 21, 2024
f2d7499
correct validation and tests
birschick-bq Nov 21, 2024
e7bea68
test information
birschick-bq Nov 21, 2024
9941b04
correct file size check and tests
birschick-bq Nov 22, 2024
7d7c7ce
correct tests
birschick-bq Nov 22, 2024
60646ff
correct tests
birschick-bq Nov 22, 2024
879b41d
correct tests
birschick-bq Nov 22, 2024
6c1d330
correct tests - larger size and range
birschick-bq Nov 22, 2024
65cbc95
correct tests - invalid file characters
birschick-bq Nov 22, 2024
d072479
correct tests - max trace files
birschick-bq Nov 22, 2024
1d68327
correct tests - single trace file
birschick-bq Nov 22, 2024
a3b9584
refactor where tracing options are handled. handle options for file s…
birschick-bq Nov 22, 2024
40dad00
remove tracing of all properties/options - might include tokens and p…
birschick-bq Nov 22, 2024
a3d84c9
validate trace folder is writable
birschick-bq Nov 22, 2024
be09ea8
ensure folder before folder validation
birschick-bq Nov 22, 2024
94ae794
update Spark driver documentation for file tracing options
birschick-bq Nov 22, 2024
fa2dca6
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Nov 27, 2024
04e19c1
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Nov 29, 2024
9c6a420
initial commit for setting the traceParent
birschick-bq Nov 29, 2024
69d4345
small fixes for setting the traceParent
birschick-bq Nov 29, 2024
afd7ea6
small doc updates
birschick-bq Nov 29, 2024
8bd877a
refactored how boiler place code is handled
birschick-bq Nov 30, 2024
7b58323
some renameing and coumentation
birschick-bq Nov 30, 2024
015bc90
fixed formatting
birschick-bq Nov 30, 2024
cb79fa7
add improved test for traceParent.
birschick-bq Dec 3, 2024
4ac1789
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Dec 3, 2024
cb3b6f2
update tests
birschick-bq Dec 3, 2024
50e16e4
Improvement for output format and ingestion. Improvements for tracePa…
birschick-bq Dec 5, 2024
1cd083f
Add extension methods to ease of creating Events and Links
birschick-bq Dec 5, 2024
9f182b4
Documentation update
birschick-bq Dec 5, 2024
12882ab
Add public property for ActivitySourceName
birschick-bq Dec 5, 2024
600735d
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Dec 10, 2024
fe60b80
Merge branch 'main' into dev/birschick-bq/open-telemetry-poc
birschick-bq Dec 10, 2024
6d29577
remove instrumentation to isolate library change
birschick-bq Dec 11, 2024
21548c1
remove more instrumentation code
birschick-bq Dec 11, 2024
304a0c5
remove more instrumentation code #2
birschick-bq Dec 11, 2024
2797b54
remove more instrumentation code #3
birschick-bq Dec 11, 2024
d7ec6f6
Merge branch 'main' into dev/birschick-bq/tracing-base-library
birschick-bq Dec 11, 2024
41ed8e3
remove more instrumentation code #4
birschick-bq Dec 12, 2024
c3cfa50
remove more instrumentation code #5
birschick-bq Dec 12, 2024
42076b9
remove more instrumentation code #6
birschick-bq Dec 12, 2024
d58e56d
add more test content
birschick-bq Dec 20, 2024
7bca17c
Merge branch 'main' into dev/birschick-bq/tracing-base-library
birschick-bq Dec 20, 2024
39f50bb
add performance test using BenchmarkDotNet
birschick-bq Jan 3, 2025
aa069f2
add header
birschick-bq Jan 3, 2025
f27b52f
correct async invocation
birschick-bq Jan 3, 2025
7a17831
remove trailing white-space
birschick-bq Jan 3, 2025
098f4c5
simplify activity handling
birschick-bq Jan 3, 2025
96f7c95
correct performance tests and improve performance
birschick-bq Jan 10, 2025
843c726
properly implement async queue to handle activity writing in FileExpo…
birschick-bq Jan 15, 2025
bf2a77e
Merge branch 'main' into dev/birschick-bq/tracing-base-library
birschick-bq Jan 15, 2025
17f3d99
correct file size check
birschick-bq Jan 16, 2025
723deed
Merge branch 'main' into dev/birschick-bq/tracing-base-library
birschick-bq Feb 4, 2025
92a6c73
some clean-up
birschick-bq Feb 6, 2025
efe111c
fix trailing space
birschick-bq Feb 6, 2025
5481238
refactor file exporter namespace
birschick-bq Feb 7, 2025
07dba27
add clarifying comments
birschick-bq Feb 7, 2025
2894673
Merge branch 'main' into dev/birschick-bq/tracing-base-library
birschick-bq Feb 12, 2025
685534b
Initial tracing (alternative)
birschick-bq Feb 25, 2025
10526b9
Remove tracing performance stub
birschick-bq Feb 25, 2025
000267f
Cleanup #1
birschick-bq Feb 25, 2025
cd8176e
Merge branch 'main' into dev/birschick-bq/tracing-alternative
birschick-bq Feb 25, 2025
99816e5
cleanup #2
birschick-bq Feb 25, 2025
cddd2e3
cleanup #3
birschick-bq Feb 25, 2025
ad29ae1
cleanup #4
birschick-bq Feb 25, 2025
87f1783
cleanup #5
birschick-bq Feb 25, 2025
26a3239
cleanup #6
birschick-bq Feb 25, 2025
f7951aa
cleanup #7
birschick-bq Feb 25, 2025
35aaacd
add instrumentation of fetch next
birschick-bq Feb 25, 2025
bd9ef5f
correct errors
birschick-bq Feb 25, 2025
ea9d0eb
Merge branch 'main' into dev/birschick-bq/tracing-alternative
birschick-bq Mar 3, 2025
ab4784c
Merge branch 'main' into dev/birschick-bq/tracing-alternative
birschick-bq Mar 4, 2025
582911c
Implement SetOption for HiveServer2Connection
birschick-bq Mar 4, 2025
f5ead8f
Use 'this' chaining
birschick-bq Mar 4, 2025
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
1 change: 1 addition & 0 deletions csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Apache.Arrow" Version="19.0.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net6.0'))">
Expand Down
51 changes: 51 additions & 0 deletions csharp/src/Apache.Arrow.Adbc/Tracing/ActivityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

using System.Collections.Generic;
using System.Diagnostics;

namespace Apache.Arrow.Adbc.Tracing
{
public static class ActivityExtensions
{
/// <summary>
/// Add a new <see cref="ActivityEvent"/> object to the <see cref="Activity.Events" /> list.
/// </summary>
/// <param name="activity">The activity to add the event to.</param>
/// <param name="eventName">The name of the event.</param>
/// <param name="tags">The optional list of tags to attach to the event.</param>
/// <returns><see langword="this"/> for convenient chaining.</returns>
public static Activity AddEvent(this Activity activity, string eventName, IReadOnlyList<KeyValuePair<string, object?>>? tags = default)
{
ActivityTagsCollection? tagsCollection = tags == null ? null : new ActivityTagsCollection(tags);
return activity.AddEvent(new ActivityEvent(eventName, tags: tagsCollection));
}

/// <summary>
/// Add a new <see cref="ActivityLink"/> to the <see cref="Activity.Links"/> list.
/// </summary>
/// <param name="activity">The activity to add the event to.</param>
/// <param name="traceParent">The traceParent id for the associated <see cref="ActivityContext"/>.</param>
/// <param name="tags">The optional list of tags to attach to the event.</param>
/// <returns><see langword="this"/> for convenient chaining.</returns>
public static Activity AddLink(this Activity activity, string traceParent, IReadOnlyList<KeyValuePair<string, object?>>? tags = default)
{
ActivityTagsCollection? tagsCollection = tags == null ? null : new ActivityTagsCollection(tags);
return activity.AddLink(new ActivityLink(ActivityContext.Parse(traceParent, null), tags: tagsCollection));
}
}
}
351 changes: 351 additions & 0 deletions csharp/src/Apache.Arrow.Adbc/Tracing/ActivityTrace.cs

Large diffs are not rendered by default.

192 changes: 192 additions & 0 deletions csharp/src/Apache.Arrow.Adbc/Tracing/SerializableActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.Json.Serialization;

namespace Apache.Arrow.Adbc.Tracing
{
/// <summary>
/// Simplified version of <see cref="Activity"/> that excludes some properties, etc.
/// </summary>
internal class SerializableActivity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is explicitly necessary, but helps with testing. It also "could" be useful a serialized version of Activity

{
[JsonConstructor]
public SerializableActivity() { }

internal SerializableActivity(
ActivityStatusCode status,
string? statusDescription,
bool hasRemoteParent,
ActivityKind kind,
string operationName,
TimeSpan duration,
DateTime startTimeUtc,
string? id,
string? parentId,
string? rootId,
string? traceStateString,
ActivitySpanId spanId,
ActivityTraceId traceId,
bool recorded,
bool isAllDataRequested,
ActivityTraceFlags activityTraceFlags,
ActivitySpanId parentSpanId,
ActivityIdFormat idFormat,
IReadOnlyList<KeyValuePair<string, object?>> tagObjects,
IReadOnlyList<SerializableActivityEvent> events,
IReadOnlyList<SerializableActivityLink> links,
IReadOnlyList<KeyValuePair<string, string?>> baggage)
{
Status = statusDescription ?? status.ToString();
HasRemoteParent = hasRemoteParent;
Kind = kind.ToString();
OperationName = operationName;
Duration = duration;
StartTimeUtc = startTimeUtc;
Id = id;
ParentId = parentId;
RootId = rootId;
TraceStateString = traceStateString;
SpanId = spanId.ToHexString();
TraceId = traceId.ToHexString();
Recorded = recorded;
IsAllDataRequested = isAllDataRequested;
ActivityTraceFlags = activityTraceFlags.ToString();
ParentSpanId = parentSpanId.ToHexString();
IdFormat = idFormat.ToString();
TagObjects = tagObjects;
Events = events;
Links = links;
Baggage = baggage;
}

internal SerializableActivity(Activity activity) : this(
activity.Status,
activity.StatusDescription,
activity.HasRemoteParent,
activity.Kind,
activity.OperationName,
activity.Duration,
activity.StartTimeUtc,
activity.Id,
activity.ParentId,
activity.RootId,
activity.TraceStateString,
activity.SpanId,
activity.TraceId,
activity.Recorded,
activity.IsAllDataRequested,
activity.ActivityTraceFlags,
activity.ParentSpanId,
activity.IdFormat,
activity.TagObjects.ToArray(),
activity.Events.Select(e => (SerializableActivityEvent)e).ToArray(),
activity.Links.Select(l => (SerializableActivityLink)l).ToArray(),
activity.Baggage.ToArray())
{ }

public string? Status { get; set; }
public bool HasRemoteParent { get; set; }
public string? Kind { get; set; }
public string OperationName { get; set; } = "";
public TimeSpan Duration { get; set; }
public DateTime StartTimeUtc { get; set; }
public string? Id { get; set; }
public string? ParentId { get; set; }
public string? RootId { get; set; }

public string? TraceStateString { get; set; }
public string? SpanId { get; set; }
public string? TraceId { get; set; }
public bool Recorded { get; set; }
public bool IsAllDataRequested { get; set; }
public string? ActivityTraceFlags { get; set; }
public string? ParentSpanId { get; set; }
public string? IdFormat { get; set; }

public IReadOnlyList<KeyValuePair<string, object?>> TagObjects { get; set; } = [];
public IReadOnlyList<SerializableActivityEvent> Events { get; set; } = [];
public IReadOnlyList<SerializableActivityLink> Links { get; set; } = [];
public IReadOnlyList<KeyValuePair<string, string?>> Baggage { get; set; } = [];
}

internal class SerializableActivityEvent
{
/// <summary>
/// Gets the <see cref="SerializableActivityEvent"/> name.
/// </summary>
public string? Name { get; set; }

/// <summary>
/// Gets the <see cref="SerializableActivityEvent"/> timestamp.
/// </summary>
public DateTimeOffset Timestamp { get; set; }

public IReadOnlyList<KeyValuePair<string, object?>> Tags { get; set; } = [];

public static implicit operator SerializableActivityEvent(System.Diagnostics.ActivityEvent source)
{
return new SerializableActivityEvent()
{
Name = source.Name,
Timestamp = source.Timestamp,
Tags = source.Tags.ToArray(),
};
}
}

internal class SerializableActivityLink
{
public SerializableActivityContext? Context { get; set; }

public IReadOnlyList<KeyValuePair<string, object?>>? Tags { get; set; } = [];

public static implicit operator SerializableActivityLink(System.Diagnostics.ActivityLink source)
{
return new SerializableActivityLink()
{
Context = source.Context,
Tags = source.Tags?.ToArray(),
};
}
}

internal class SerializableActivityContext
{
public string? SpanId { get; set; }
public string? TraceId { get; set; }
public string? TraceState { get; set; }
public ActivityTraceFlags? TraceFlags { get; set; }
public bool IsRemote { get; set; }

public static implicit operator SerializableActivityContext(System.Diagnostics.ActivityContext source)
{
return new SerializableActivityContext()
{
SpanId = source.SpanId.ToHexString(),
TraceId = source.TraceId.ToHexString(),
TraceState = source.TraceState,
TraceFlags = source.TraceFlags,
IsRemote = source.IsRemote,
};
}
}
}
Loading
Loading