Skip to content

Commit 29e9867

Browse files
committed
feat(csharp): Implement telemetry tag definitions (phase 1)
1 parent 6608390 commit 29e9867

File tree

8 files changed

+446
-1
lines changed

8 files changed

+446
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ go.work.sum
4242
.env
4343

4444
# Editor/IDE
45-
# .idea/
45+
.idea/
4646
# .vscode/
4747

4848
# Byte-compiled / optimized / DLL files
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
using System.Collections.Generic;
19+
20+
namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.TagDefinitions
21+
{
22+
/// <summary>
23+
/// Tag definitions for Connection.Open events.
24+
/// </summary>
25+
internal static class ConnectionOpenEvent
26+
{
27+
public const string EventName = "Connection.Open";
28+
29+
// Identity
30+
[TelemetryTag("workspace.id", ExportScope = TagExportScope.ExportAll, Required = true, Description = "Workspace ID")]
31+
public const string WorkspaceId = "workspace.id";
32+
33+
[TelemetryTag("session.id", ExportScope = TagExportScope.ExportAll, Required = true, Description = "Session ID")]
34+
public const string SessionId = "session.id";
35+
36+
// Driver Configuration
37+
[TelemetryTag("driver.version", ExportScope = TagExportScope.ExportAll, Description = "Driver version")]
38+
public const string DriverVersion = "driver.version";
39+
40+
[TelemetryTag("driver.os", ExportScope = TagExportScope.ExportAll, Description = "Operating system")]
41+
public const string DriverOS = "driver.os";
42+
43+
[TelemetryTag("driver.runtime", ExportScope = TagExportScope.ExportAll, Description = ".NET runtime")]
44+
public const string DriverRuntime = "driver.runtime";
45+
46+
// Feature Flags
47+
[TelemetryTag("feature.cloudfetch", ExportScope = TagExportScope.ExportAll, Description = "CloudFetch enabled")]
48+
public const string FeatureCloudFetch = "feature.cloudfetch";
49+
50+
[TelemetryTag("feature.lz4", ExportScope = TagExportScope.ExportAll, Description = "LZ4 compression enabled")]
51+
public const string FeatureLz4 = "feature.lz4";
52+
53+
[TelemetryTag("feature.direct_results", ExportScope = TagExportScope.ExportAll, Description = "Direct results enabled")]
54+
public const string FeatureDirectResults = "feature.direct_results";
55+
56+
[TelemetryTag("feature.multiple_catalog", ExportScope = TagExportScope.ExportAll, Description = "Multiple catalog enabled")]
57+
public const string FeatureMultipleCatalog = "feature.multiple_catalog";
58+
59+
[TelemetryTag("feature.trace_propagation", ExportScope = TagExportScope.ExportAll, Description = "Trace propagation enabled")]
60+
public const string FeatureTracePropagation = "feature.trace_propagation";
61+
62+
[TelemetryTag("server.address", ExportScope = TagExportScope.ExportLocal, Description = "Server address")]
63+
public const string ServerAddress = "server.address";
64+
65+
/// <summary>
66+
/// Returns tags allowed for Databricks export (privacy filter).
67+
/// </summary>
68+
public static IReadOnlyCollection<string> GetDatabricksExportTags()
69+
{
70+
return new HashSet<string>
71+
{
72+
WorkspaceId,
73+
SessionId,
74+
DriverVersion,
75+
DriverOS,
76+
DriverRuntime,
77+
FeatureCloudFetch,
78+
FeatureLz4,
79+
FeatureDirectResults,
80+
FeatureMultipleCatalog,
81+
FeatureTracePropagation
82+
};
83+
}
84+
}
85+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
using System.Collections.Generic;
19+
20+
namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.TagDefinitions
21+
{
22+
/// <summary>
23+
/// Tag definitions for Error events.
24+
/// </summary>
25+
internal static class ErrorEvent
26+
{
27+
public const string EventName = "Error";
28+
29+
// Error Classification
30+
[TelemetryTag("error.type", ExportScope = TagExportScope.ExportAll, Required = true, Description = "Error type")]
31+
public const string ErrorType = "error.type";
32+
33+
[TelemetryTag("http.status_code", ExportScope = TagExportScope.ExportAll, Description = "HTTP status code")]
34+
public const string HttpStatusCode = "http.status_code";
35+
36+
[TelemetryTag("db.sql_state", ExportScope = TagExportScope.ExportAll, Description = "SQL state")]
37+
public const string DbSqlState = "db.sql_state";
38+
39+
[TelemetryTag("error.operation", ExportScope = TagExportScope.ExportAll, Description = "Failed operation")]
40+
public const string ErrorOperation = "error.operation";
41+
42+
[TelemetryTag("error.retried", ExportScope = TagExportScope.ExportAll, Description = "Was retried")]
43+
public const string ErrorRetried = "error.retried";
44+
45+
[TelemetryTag("error.retry_count", ExportScope = TagExportScope.ExportAll, Description = "Retry count")]
46+
public const string ErrorRetryCount = "error.retry_count";
47+
48+
[TelemetryTag("error.message", ExportScope = TagExportScope.ExportLocal, Description = "Error message")]
49+
public const string ErrorMessage = "error.message";
50+
51+
[TelemetryTag("error.stack_trace", ExportScope = TagExportScope.ExportLocal, Description = "Stack trace")]
52+
public const string ErrorStackTrace = "error.stack_trace";
53+
54+
/// <summary>
55+
/// Returns tags allowed for Databricks export (privacy filter).
56+
/// </summary>
57+
public static IReadOnlyCollection<string> GetDatabricksExportTags()
58+
{
59+
return new HashSet<string>
60+
{
61+
ErrorType,
62+
HttpStatusCode,
63+
DbSqlState,
64+
ErrorOperation,
65+
ErrorRetried,
66+
ErrorRetryCount
67+
};
68+
}
69+
}
70+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
using System.Collections.Generic;
19+
20+
namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.TagDefinitions
21+
{
22+
/// <summary>
23+
/// Tag definitions for Statement execution events.
24+
/// </summary>
25+
internal static class StatementExecutionEvent
26+
{
27+
public const string EventName = "Statement.Execute";
28+
29+
// Identity
30+
[TelemetryTag("statement.id", ExportScope = TagExportScope.ExportAll, Required = true, Description = "Statement ID")]
31+
public const string StatementId = "statement.id";
32+
33+
[TelemetryTag("session.id", ExportScope = TagExportScope.ExportAll, Required = true, Description = "Session ID")]
34+
public const string SessionId = "session.id";
35+
36+
// Result Metrics
37+
[TelemetryTag("result.format", ExportScope = TagExportScope.ExportAll, Description = "Result format")]
38+
public const string ResultFormat = "result.format";
39+
40+
[TelemetryTag("result.chunk_count", ExportScope = TagExportScope.ExportAll, Description = "Chunk count")]
41+
public const string ResultChunkCount = "result.chunk_count";
42+
43+
[TelemetryTag("result.bytes_downloaded", ExportScope = TagExportScope.ExportAll, Description = "Bytes downloaded")]
44+
public const string ResultBytesDownloaded = "result.bytes_downloaded";
45+
46+
[TelemetryTag("result.compression_enabled", ExportScope = TagExportScope.ExportAll, Description = "Compression enabled")]
47+
public const string ResultCompressionEnabled = "result.compression_enabled";
48+
49+
[TelemetryTag("result.row_count", ExportScope = TagExportScope.ExportAll, Description = "Row count")]
50+
public const string ResultRowCount = "result.row_count";
51+
52+
// Polling Metrics
53+
[TelemetryTag("poll.count", ExportScope = TagExportScope.ExportAll, Description = "Poll count")]
54+
public const string PollCount = "poll.count";
55+
56+
[TelemetryTag("poll.latency_ms", ExportScope = TagExportScope.ExportAll, Description = "Poll latency")]
57+
public const string PollLatencyMs = "poll.latency_ms";
58+
59+
// Operation Type
60+
[TelemetryTag("db.operation", ExportScope = TagExportScope.ExportAll, Description = "Operation type")]
61+
public const string DbOperation = "db.operation";
62+
63+
[TelemetryTag("db.statement", ExportScope = TagExportScope.ExportLocal, Description = "SQL statement")]
64+
public const string DbStatement = "db.statement";
65+
66+
[TelemetryTag("db.catalog", ExportScope = TagExportScope.ExportLocal, Description = "Catalog name")]
67+
public const string DbCatalog = "db.catalog";
68+
69+
[TelemetryTag("db.schema", ExportScope = TagExportScope.ExportLocal, Description = "Schema name")]
70+
public const string DbSchema = "db.schema";
71+
72+
public static IReadOnlyCollection<string> GetDatabricksExportTags()
73+
{
74+
return new HashSet<string>
75+
{
76+
StatementId,
77+
SessionId,
78+
ResultFormat,
79+
ResultChunkCount,
80+
ResultBytesDownloaded,
81+
ResultCompressionEnabled,
82+
ResultRowCount,
83+
PollCount,
84+
PollLatencyMs,
85+
DbOperation
86+
};
87+
}
88+
}
89+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.TagDefinitions
19+
{
20+
/// <summary>
21+
/// Defines the types of telemetry events that can be emitted by the driver.
22+
/// Each event type has its own set of allowed tags defined in corresponding *Event classes.
23+
/// </summary>
24+
public enum TelemetryEventType
25+
{
26+
/// <summary>
27+
/// Connection open event. Emitted when a connection is established.
28+
/// Tags defined in: <see cref="ConnectionOpenEvent"/>
29+
/// </summary>
30+
ConnectionOpen,
31+
32+
/// <summary>
33+
/// Statement execution event. Emitted when a query or statement is executed.
34+
/// Tags defined in: <see cref="StatementExecutionEvent"/>
35+
/// </summary>
36+
StatementExecution,
37+
38+
/// <summary>
39+
/// Error event. Emitted when an error occurs during any operation.
40+
/// Tags defined in: <see cref="ErrorEvent"/>
41+
/// </summary>
42+
Error
43+
}
44+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
using System;
19+
20+
namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.TagDefinitions
21+
{
22+
/// <summary>
23+
/// Controls where telemetry tags can be exported.
24+
/// </summary>
25+
[Flags]
26+
internal enum TagExportScope
27+
{
28+
None = 0,
29+
ExportLocal = 1, // Local diagnostics only
30+
ExportDatabricks = 2, // Safe for Databricks service
31+
ExportAll = ExportLocal | ExportDatabricks
32+
}
33+
34+
/// <summary>
35+
/// Attribute for defining telemetry tags with export controls.
36+
/// </summary>
37+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
38+
internal sealed class TelemetryTagAttribute : Attribute
39+
{
40+
public string TagName { get; }
41+
public TagExportScope ExportScope { get; set; }
42+
public string? Description { get; set; }
43+
public bool Required { get; set; }
44+
45+
public TelemetryTagAttribute(string tagName)
46+
{
47+
TagName = tagName ?? throw new ArgumentNullException(nameof(tagName));
48+
ExportScope = TagExportScope.ExportLocal;
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)