Coder Social home page Coder Social logo

tonyredondo / dd-sdk-swift-testing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datadog/dd-sdk-swift-testing

0.0 2.0 0.0 831 KB

Datadog Test Instrumentation framework for Swift / ObjC

License: Apache License 2.0

Swift 92.43% Objective-C 4.69% Makefile 1.30% C 1.58%

dd-sdk-swift-testing's Introduction

Datadog SDK for Swift testing

Datadog Test Instrumentation framework for Swift / ObjC

Getting Started

Link your test targets with the framework (you can use SPM or direct linking )

Set the following environment variables to the Test Action:

DD_TEST_RUNNER=1
DATADOG_CLIENT_TOKEN=<your current client token>
SRCROOT=$(SRCROOT)

You my want to set other environment variables to

DD_ENV=<The environment you want to report>
DD_SERVICE=<The name of the service you want to report>

Depending on your CI service, you must also set the environment variables to be read from the test executions. See DDEnvironmentValues.swift for details of your specific CI.

For example for Bitrise, they should be:

BITRISE_SOURCE_DIR=$(BITRISE_SOURCE_DIR)
BITRISE_APP_TITLE=$(BITRISE_APP_TITLE)
BITRISE_BUILD_SLUG=$(BITRISE_BUILD_SLUG)
BITRISE_BUILD_NUMBER=$(BITRISE_BUILD_NUMBER)
BITRISE_BUILD_URL=$(BITRISE_BUILD_URL)

UITests

For UITests, both the test target and the application running from the UITests must link with the framework, environment variables only need to be set in the test target, since the framework automatically injects these values to the application.

Disabling Auto Instrumentation

The framework automatically tries to capture the maximum information, but for some situations or tests it can be counter-productive. You can disable some of the autoinstrumentation for all the tests, by setting the following environment variables.

Boolean variables can use any of: "1","0","true","false", "YES", "NO" String List variables accepts a list of elements separated by "," or ";"

DD_DISABLE_NETWORK_INSTRUMENTATION # Disables all network instrumentation (Boolean)
DD_DISABLE_STDOUT_INSTRUMENTATION # Disables all stdout instrumentation (Boolean)
DD_DISABLE_STDERR_INSTRUMENTATION # Disables all stderr instrumentation (Boolean)

Network Auto Instrumentation

For Network autoinstrumentation there are other settings that you can configure

DD_DISABLE_HEADERS_INJECTION # Disables all injection of tracing headers (Boolean)
DD_INSTRUMENTATION_EXTRA_HEADERS # Specific extra headers that you want the tool to log (String List)
DD_EXCLUDED_URLS # Urls that you dont want to log or inject headers into(String List)
DD_ENABLE_RECORD_PAYLOAD # It enables reporting a subset of the payloads in requests and responses (Boolean)
DD_MAX_PAYLOAD_SIZE # It sets the maximum size that will be reported from the payload, 1024 by default (Integer)

You can also disable or enable specific autoinstrumentation in some of the tests from Swift or Objective-C by importing the module DatadogSDKTesting and using the class: DDInstrumentationControl.

Disable crash handling

You should never need to do it, but in some very specific cases you may want to disable crash reporting for tests (e.g. you want to test your own crash handler, ... ):

DD_DISABLE_CRASH_HANDLER # Disables crash handling and reporting. (Boolean) WARNING, read note below

You must know that if you disable crash reporting, crashing tests wont be reported to the backend and wont appear as a failure. If you really, really need to do this for any of your tests, run it as a totally separated target, so you dont disable it for the rest of the tests

Adding custom tags

Using environment variables

You can use DD_TAGS environment variable. It must contain pairs of key:tag separated by spaces. For example:

DDTAGS=tag-key-0:tag-value-0 tag-key-1:tag-value-1

If one of your values starts with the $ character, it will be replaced with the environment variable with the same name if it exists, example:

DDTAGS=home:$HOME

It also supports replacing a environment variable at the beggining of the value if contains non env variables supported characters (a-z, A-Z or _):

FOO = BAR
DD_TAGS=key1:$FOO-v1 // expected: key1:BAR-v1

Using OpenTelemetry (only for Swift)

Datadog swift testing framework uses OpenTelemetry as the tracing technology under the hood. You can access the OpenTelemetry tracer using DDInstrumentationControl.openTelemetryTracer and can use any OpenTelemetry api. For example, for adding a tag/attribute

let tracer = DDInstrumentationControl.openTelemetryTracer
tracer?.activeSpan?.setAttribute(key: "OTelTag", value: "OTelValue")

Test target needs to link explicitly with OpenTelemetry

Contributing

Pull requests are welcome. First, open an issue to discuss what you would like to change. For more information, read the Contributing Guide.

License

Apache License, v2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.