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

Add DataDog logging code #35

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This sample is designed to work with [DataDog Application Performance Monitoring

To run this sample, you will need a copy of your DataDog API Key - which will be passed into the local Kubernetes cluster created by this tutorial.

To [get your DataDog API Key for use with DataDog's Helm Agent, click here](https://app.datadoghq.com/account/settings#agent/kubernetes).
**To [get your DataDog API Key for use with DataDog's Helm Agent, click here](https://app.datadoghq.com/account/settings#agent/kubernetes)**.

### Retreiving the DataDog Helm Charts
This sample uses [Helm](https://helm.sh/) to install [DataDog's Agent Helm Chart](https://github.com/DataDog/helm-charts/blob/master/charts/datadog/README.md) into a local Kubernetes cluster.
Expand Down
4 changes: 2 additions & 2 deletions k8s/datadog/datadog-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ datadog:
logs:
# datadog.logs.enabled -- Enables this to activate Datadog Agent log collection
## ref: https://docs.datadoghq.com/agent/basic_agent_usage/kubernetes/#log-collection-setup
enabled: false
enabled: true

# datadog.logs.containerCollectAll -- Enable this to allow log collection for all containers
## ref: https://docs.datadoghq.com/agent/basic_agent_usage/kubernetes/#log-collection-setup
containerCollectAll: false
containerCollectAll: true

# datadog.logs.containerCollectUsingFiles -- Collect logs from files in /var/log/pods instead of using container runtime API
## It's usually the most efficient way of collecting logs.
Expand Down
6 changes: 5 additions & 1 deletion k8s/environment/configs/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ metadata:
name: pb-configs
data:
# Configuration values can be set as key-value properties
environment: Development
environment: "Development"
dd-service: "akka.cluster"
dd-dogstatsd-port: "8125"
dd-trace-agent-port: "8126"
dd-apm-receiver-port: "8126"
28 changes: 28 additions & 0 deletions k8s/services/petabridge.phobos.web.datadog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,38 @@ spec:
configMapKeyRef:
name: pb-configs
key: environment
- name: DD_ENV
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/env']
- name: DD_SERVICE
valueFrom:
configMapKeyRef:
name: pb-configs
key: dd-service
- name: DD_VERSION
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/version']
- name: DD_AGENT_HOST
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: DD_DOGSTATSD_PORT
valueFrom:
configMapKeyRef:
name: pb-configs
key: dd-dogstatsd-port
- name: DD_TRACE_AGENT_PORT
valueFrom:
configMapKeyRef:
name: pb-configs
key: dd-trace-agent-port
- name: DD_APM_RECEIVER_PORT
valueFrom:
configMapKeyRef:
name: pb-configs
key: dd-apm-receiver-port
- name: DD_API_KEY
valueFrom:
secretKeyRef:
Expand Down
17 changes: 17 additions & 0 deletions src/Petabridge.Phobos.Web.DataDog/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@ COPY --from=base /root/.dotnet /root/.dotnet/
# Needed because https://stackoverflow.com/questions/51977474/install-dotnet-core-tool-dockerfile
ENV PATH="${PATH}:/root/.dotnet/tools"

# Please select the corresponding download for your Linux containers https://github.com/DataDog/dd-trace-dotnet/releases/latest

# Download and install the Tracer
RUN mkdir -p /opt/datadog \
&& mkdir -p /var/log/datadog \
&& TRACER_VERSION=$(curl -s https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c2-) \
&& curl -LO https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb \
&& dpkg -i ./datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb \
&& rm ./datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb

# Enable the tracer
ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
ENV DD_DOTNET_TRACER_HOME=/opt/datadog
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json

CMD ["dotnet", "Petabridge.Phobos.Web.DataDog.dll"]
11 changes: 4 additions & 7 deletions src/Petabridge.Phobos.Web.DataDog/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void ConfigureAppMetrics(IServiceCollection services)
.Report.ToStatsDUdp(opt =>
{
opt.SocketSettings.Address = Environment.GetEnvironmentVariable("DD_AGENT_HOST");
opt.SocketSettings.Port = 8125;
opt.SocketSettings.Port = int.Parse(Environment.GetEnvironmentVariable("DD_DOGSTATSD_PORT"));
opt.SocketSettings.MaxUdpDatagramSize = 1024 * 4;
opt.StatsDOptions.MetricNameFormatter = new DefaultDogStatsDMetricStringSerializer();
})
Expand All @@ -98,10 +98,8 @@ public static void ConfigureAppMetrics(IServiceCollection services)
public static void ConfigureDataDogTracing(IServiceCollection services)
{
// Add DataDog Tracing
services.AddSingleton<ITracer>(sp =>
{
return OpenTracingTracerFactory.CreateTracer().WithScopeManager(new ActorScopeManager());
});
var tracer = OpenTracingTracerFactory.CreateTracer().WithScopeManager(new ActorScopeManager());
services.AddSingleton<ITracer>(tracer);
}

public static void ConfigureAkka(IServiceCollection services)
Expand All @@ -119,8 +117,7 @@ public static void ConfigureAkka(IServiceCollection services)
.WithTracing(t => t.SetTracer(tracer))) // binds Phobos to same tracer as ASP.NET Core
.WithSetup(BootstrapSetup.Create()
.WithConfig(config) // passes in the HOCON for Akka.NET to the ActorSystem
.WithActorRefProvider(PhobosProviderSelection
.Cluster)); // last line activates Phobos inside Akka.NET
.WithActorRefProvider(PhobosProviderSelection.Cluster)); // last line activates Phobos inside Akka.NET

var sys = ActorSystem.Create("ClusterSys", phobosSetup);

Expand Down
1 change: 1 addition & 0 deletions src/Petabridge.Phobos.Web.DataDog/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ petabridge.cmd{
}

akka {
loggers = ["Akka.Event.DefaultLogger", "Phobos.Tracing.DataDogLogger, Phobos.Tracing"]
actor {
provider = cluster

Expand Down
4 changes: 2 additions & 2 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Copyright>Copyright © 2019-2021 Petabridge</Copyright>
<Authors>Petabridge</Authors>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionPrefix>0.1.1</VersionPrefix>
<PackageReleaseNotes>First release</PackageReleaseNotes>
<PackageIconUrl>
</PackageIconUrl>
Expand All @@ -24,4 +24,4 @@
<FluentAssertionsVersion>6.2.0</FluentAssertionsVersion>
<PhobosVersion>1.2.5</PhobosVersion>
</PropertyGroup>
</Project>
</Project>