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

Name collisions caused by the module name being Datadog + having a class named Datadog + having a class named Logger #250

Closed
bsrz opened this issue Sep 10, 2020 · 5 comments
Assignees
Labels
2.0 compilation issue SDK doesn't compile or gives warnings.

Comments

@bsrz
Copy link

bsrz commented Sep 10, 2020

The issue

Apple introduced a new Logger class in iOS 14, and most project have some kind of Logger class as a layer of abstraction.

import Datadog

let logger: Logger // ❗ ambiguous class name
import Datadog

let logger: Datadog.Logger // ❗ the compile thinks we're talking about the class, which doesn't have a nested class named `Logger` therefore cannot find class `Datadog.Logger`
import class Datadog.Logger 

let logger: Datadog.Logger // ✅
let config: Datadog.Configuration // ❗ import statement only imports the Logger class, unknown `Datadog.Configuration` class
let context: Datadog.AppContext // ❗ import statement only imports the Logger class, unknown `Datadog.Configuration` class

This is just an annoying import dance cause solely by the fact that the module contains a class of the same name.


Datadog SDK version:

_Which version of the Datadog SDK causes this problem?
1.3.1

Last working Datadog SDK version:

_What is the last Datadog SDK version where this problem didn't occur?
n/a

Dependency Manager:

_Which dependency manager do you use?
Cocoapods

Xcode version:

Xcode 11.7 (11E801a)

Swift version:

5.2.4

The Solution

Rename the module to DatadogSDK or any other name than the Datadog class.
Or rename the Datadog class to something like DatadogClient.

@bsrz bsrz added the compilation issue SDK doesn't compile or gives warnings. label Sep 10, 2020
@ncreated
Copy link
Member

Hey @bsarrazin 👋. Thanks for using Datadog 🙂! To avoid the name collision and compiler ambiguity we provide the DDLogger typealias:

/// Usage:
///
/// import Datadog
///
/// // logger reference
/// var logger: DDLogger!
///
/// // instantiate Datadog logger
/// logger = DDLogger.builder.build()
///
public typealias DDLogger = Logger

which may be used as a workaround.

But the argument on Apple's Logger is totally valid and we may want to consider tackling it in some other way. Let me know if it fixes the issue for now 🙌.

@ncreated ncreated added the awaiting response Waiting for response / confirmation from the reporter label Sep 10, 2020
@ncreated ncreated self-assigned this Sep 10, 2020
@bsrz
Copy link
Author

bsrz commented Sep 10, 2020

@ncreated thanks for that, I definitely missed that alias.
That fixed it as a workaround, thank you 👍

@ncreated
Copy link
Member

Thanks for the update @bsarrazin 👌. Because this is a 3rd GH Issue on this topic (1st, 2nd) I have bumped the priority of this enhancement in our backlog. No exact ETA, but this should be addressed soon. Feel free to close this issue if you consider it solved.

@ncreated ncreated removed the awaiting response Waiting for response / confirmation from the reporter label Dec 9, 2020
@simonpierreroy
Copy link

Renaming the Datadog class would also remove the need to add global typealias (For Global and LogLevel) since Datadog.XYZ could be used instead. My team copied the repository internally and renamed the class...

@maxep
Copy link
Member

maxep commented Jul 31, 2023

Fixed in 2.0.

@maxep maxep closed this as completed Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 compilation issue SDK doesn't compile or gives warnings.
Projects
None yet
Development

No branches or pull requests

4 participants